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

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  4. Subject:  v32i064:  ecu - ECU Asynchronous Communications v3.20, Part29/40
  5. Message-ID: <1992Sep14.145014.22387@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: afc5eb1d91b15c2c5dcc79a2af71c77a
  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:14 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 1894
  14.  
  15. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  16. Posting-number: Volume 32, Issue 64
  17. Archive-name: ecu/part29
  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.29 (part 29 of ecu320)
  24. # do not concatenate these parts, unpack them in order with /bin/sh
  25. # file gendial/dceT2500.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" != 29; 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/dceT2500.c'
  41. else
  42. echo 'x - continuing file gendial/dceT2500.c'
  43. sed 's/^X//' << 'SHAR_EOF' >> 'gendial/dceT2500.c' &&
  44. X    }
  45. X    if(dialer_codes['U' - 'A'])
  46. X    {
  47. X        DEBUG(5,"UUCP requested\n",0);
  48. X        strcat(cmd,"S111=30");
  49. X        s111_set++;
  50. X    }
  51. X    if(dialer_codes['M' - 'A'])
  52. X    {
  53. X        DEBUG(5,"MNP requested\n",0);
  54. X        strcat(cmd,"S95=1");
  55. X    }
  56. X
  57. X    if(dialer_codes['V' - 'A'])
  58. X    {
  59. X        DEBUG(5,"V.32 requested\n",0);
  60. X        if(hiCBAUD != B9600)
  61. X        {
  62. X            DEBUG(1,"V.32 baud rate not 9600\n",0);
  63. X            return(RC_FAIL | RCE_SPEED);
  64. X        }
  65. X        if((dialer_codes['P' - 'A']) || s111_set)
  66. X        {
  67. X            DEBUG(1,"both PEP and V.32 requested\n",0);
  68. X            return(RC_FAIL | RCE_ARGS);
  69. X        }
  70. X        strcat(cmd,"S50=6");
  71. X    }
  72. X
  73. X    if((dialer_codes['P' - 'A']) || s111_set ||
  74. X        ((hiCBAUD >= B9600) && (!dialer_codes['V' - 'A'])))
  75. X    {
  76. X        if(hiCBAUD < B9600)
  77. X        {
  78. X            DEBUG(1,"baud rate not high enough for PEP\n",0);
  79. X            return(RC_FAIL | RCE_SPEED);
  80. X        }
  81. X        if(dialer_codes['P' - 'A'])
  82. X            DEBUG(5,"PEP requested\n",0);
  83. X        else
  84. X            DEBUG(5,"PEP inferred: speed >= 9600 and no V.32 requested\n",0);
  85. X
  86. X        dialer_codes['P' - 'A'] = 1;
  87. X        strcat(cmd,"S50=255");
  88. X    }
  89. X
  90. X    init_T2500();
  91. X
  92. X    DEBUG(2,"--> issuing default setup command\n",0);
  93. X    lwrite(dialout_default);
  94. X    if(lread(5) != rOk)
  95. X    {
  96. X        DEBUG(1,"default dialout setup failed\n",0);
  97. X        return(RC_FAIL | RCE_NULL);
  98. X    }
  99. X
  100. X/* issue the custom setup command */
  101. X    if(*cptr)
  102. X    {
  103. X        DEBUG(2,"--> issuing custom setup cmd\n",0);
  104. X        strcat(cmd,"\r");
  105. X        lwrite(cmd);
  106. X        if(lread(5) != rOk)
  107. X        {
  108. X            DEBUG(1,"custom modem setup failed\n",0);
  109. X            return(RC_FAIL | RCE_NULL);
  110. X        }
  111. X    }
  112. X
  113. X/*
  114. X * calculate a timeout for the connect
  115. X * allow a minimum of 40 seconds, but if V.32 or PEP, 90
  116. X * also if long distance (North American calculation here)
  117. X * make it 132 (S7 is calculated as timeout * .9)
  118. X */
  119. X    timeout = 40;
  120. X    if((phone[0] == '1') && (phone[0] != '0'))
  121. X        timeout = 132;
  122. X    if((timeout < 90) && (dialer_codes['V' - 'A'] || dialer_codes['P' - 'A']))
  123. X        timeout = 90;
  124. X    for(cptr = phone; cptr = strchr(cptr,','); cptr++)
  125. X        timeout += 2;    /* add extra time for pause characters */
  126. X    DEBUG(4,"wait for connect = %d seconds\n",timeout);
  127. X
  128. X/* indicate non-root should not see DTE->DCE traffic */
  129. X    secure = 1;
  130. X
  131. X/*
  132. X * build and issue the actual dialing command
  133. X * if root, let him see number, otherwise just say "remote system"
  134. X */
  135. X    DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid)
  136. X        ? "remote system" : telno_str);
  137. X#ifdef WHT
  138. X    if(!strncmp(*gargv,"ECU",3))
  139. X        dialer_codes['S' - 'A'] = 1;
  140. X#endif
  141. X    sprintf(cmd,"ATM%dS7=%dDT%s\r",
  142. X        ((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
  143. X        (timeout * 9) / 10, phone);
  144. X
  145. X    /* cmd string can only be 80 characters including "AT" */
  146. X    if(strlen(cmd) > 80)
  147. X    {
  148. X        DEBUG(1,"phone number string too long\n",0);
  149. X        cleanup(RC_FAIL | RCE_PHNO);
  150. X    }
  151. X
  152. X    lwrite(cmd);
  153. X
  154. X/* indicate non-root can see DTE->DCE traffic */
  155. X    secure = 0;
  156. X
  157. X/* wait for connect */
  158. XWAIT_FOR_CONNECT:
  159. X    time(&then);
  160. X    result = lread(timeout);
  161. X    if(!(result & rfConnect))
  162. X    {
  163. X        switch(result & rfMASK)
  164. X        {
  165. X        case rNoCarrier:
  166. X            return(RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));
  167. X        case rNoDialTone:
  168. X            return(RC_FAIL | RCE_NOTONE);
  169. X        case rBusy:
  170. X            return(RC_FAIL | RCE_BUSY);
  171. X        case rNoAnswer:
  172. X            return(RC_FAIL | RCE_ANSWER);
  173. X        case rRring:
  174. X            if(rrings++ >= RRING_MAX)
  175. X                return(RC_FAIL | RCE_ANSWER);
  176. X            time(&now);
  177. X            if((timeout -= ((int)(then - now))) > 0)
  178. X                goto WAIT_FOR_CONNECT;
  179. X        case rError:
  180. X        default:
  181. X            return(RC_FAIL | RCE_NULL);
  182. X        }
  183. X    }
  184. X
  185. X    return(0);        /* succeeded */
  186. X
  187. X}    /* end of DCE_dial */
  188. X
  189. X/**********************************************************
  190. X*  You probably do not need to modify the code below here *
  191. X**********************************************************/
  192. X
  193. X/*+-------------------------------------------------------------------------
  194. X    DCE_abort(sig) - dial attempt aborted
  195. X
  196. X sig =  0 if non-signal abort (read timeout, most likely)
  197. X     != 0 if non-SIGALRM signal caught
  198. X
  199. X extern int dialing set  1 if dialing request was active,
  200. X                    else 0 if hangup request was active
  201. X
  202. XThis is a chance for the DCE-specific code to do anything it
  203. Xneeds to clean up after a failure.  Note that if a dialing
  204. Xcall fails, it is the responsibility of the higher-level
  205. Xprogram calling the dialer to call it again with a hangup request, so
  206. Xthis function is usually a no-op.
  207. X--------------------------------------------------------------------------*/
  208. Xvoid
  209. XDCE_abort(sig)
  210. Xint sig;
  211. X{
  212. X    DEBUG(10,"DCE_abort(%d);\n",sig);
  213. X}    /* end of DCE_abort */
  214. X
  215. X/*+-------------------------------------------------------------------------
  216. X    DCE_exit(exitcode) - "last chance for gas" in this incarnation
  217. X
  218. XThe independent portion of the dialer program calls this routine in
  219. Xlieu of exit() in every case except one (see DCE_argv_hook() below).
  220. XNormally, this function just passes it's argument to exit(), but
  221. Xany necessary post-processing can be done.  The function must,
  222. Xhowever, eventually call exit(exitcode);
  223. X--------------------------------------------------------------------------*/
  224. Xvoid
  225. XDCE_exit(exitcode)
  226. Xint exitcode;
  227. X{
  228. X    DEBUG(10,"DCE_exit(%d);\n",exitcode);
  229. X    exit(exitcode);
  230. X}    /* end of DCE_exit */
  231. X
  232. X/*+-------------------------------------------------------------------------
  233. X    DCE_argv_hook(argc,argv,optind,unrecognized_switches)
  234. X
  235. XThis hook gives DCE-specific code a chance to look over the entire
  236. Xcommand line, such as for -z Telebit processing.
  237. X
  238. Xargc andf argv are the same values passed to main(),
  239. X
  240. Xoptind is the value of optind at the end of normal getopt processing.
  241. X
  242. Xunrecognized_switches is the count of switches not handled by main().
  243. XSpecifically, -h and -x are standard switches.
  244. X
  245. XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
  246. Xany unrecognized switches, otherwise zero.  If you keep your nose clean
  247. Xthough, you can do anything you need to do here and exit the program.
  248. X
  249. XNote: only simple switches (with no argument) may be used with this
  250. Xfacility if the functrion is to return,' since main()'s getopt() will
  251. Xstop processing switches if it runs into an unrecognized switch with an
  252. Xargument.
  253. X
  254. XIf the function returns a non-zero value, then the value will be passed
  255. XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
  256. Xof the format expected by dialer program callers, with RC_FAIL set as a
  257. Xminimum.
  258. X--------------------------------------------------------------------------*/
  259. Xint
  260. XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
  261. Xint argc;
  262. Xchar **argv;
  263. Xint optind;
  264. Xint unrecognized_switches;
  265. X{
  266. X    if(unrecognized_switches)
  267. X        return(RC_FAIL | RCE_ARGS);
  268. X    return(0);
  269. X}    /* end of DCE_argv_hook */
  270. X
  271. X/* vi: set tabstop=4 shiftwidth=4: */
  272. SHAR_EOF
  273. echo 'File gendial/dceT2500.c is complete' &&
  274. chmod 0644 gendial/dceT2500.c ||
  275. echo 'restore of gendial/dceT2500.c failed'
  276. Wc_c="`wc -c < 'gendial/dceT2500.c'`"
  277. test 19001 -eq "$Wc_c" ||
  278.     echo 'gendial/dceT2500.c: original size 19001, current size' "$Wc_c"
  279. rm -f _shar_wnt_.tmp
  280. fi
  281. # ============= gendial/dceT3000.c ==============
  282. if test -f 'gendial/dceT3000.c' -a X"$1" != X"-c"; then
  283.     echo 'x - skipping gendial/dceT3000.c (File already exists)'
  284.     rm -f _shar_wnt_.tmp
  285. else
  286. > _shar_wnt_.tmp
  287. echo 'x - extracting gendial/dceT3000.c (Text)'
  288. sed 's/^X//' << 'SHAR_EOF' > 'gendial/dceT3000.c' &&
  289. X/*+-------------------------------------------------------------------------
  290. X    dceT3000.c - DCE-specific portion of generic SCO UUCP dialer
  291. X    Driver for Telebit T3000
  292. X    wht@n4hgf.Mt-Park.GA.US
  293. X
  294. Xdialing registers for V.32
  295. X
  296. XT3000SA - Version LA3.00 - Active Configuration
  297. X B1  E0  L2  M0  P   Q2  V1  X12  Y0 
  298. X&C1 &D2 &G0 &J0 &L0 &Q0 &R3 &S0 &T4 &X0 
  299. XS000=0   S001=0   S002:1   S003=13  S004=10  S005=8   S006=2   S007=40 
  300. XS008=2   S009=6   S010=14  S011:50  S012=50  S018=0   S025=5   S026=1  
  301. XS038=0   S041=0   S045=0   S046=0   S047=4   S048:1   S050:6   S051:252
  302. XS056=17  S057=19  S058:2   S059=0   S060=0   S061=1   S062:25  S063=0  
  303. XS064=0   S068=255 S069=0   S090=0   S093=8   S094=1   S100=0   S102=0  
  304. XS104=0   S105=1   S111=255 S112=1   S180=2   S181=1   S183=25  S190=1  
  305. XS253=10  S254=255 S255=255 
  306. X--------------------------------------------------------------------------*/
  307. X/*+:EDITS:*/
  308. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  309. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  310. X/*:05-11-1992-17:51-wht@gyro-convert dceT2500 for a preliminary version */
  311. X
  312. X#include "dialer.h"
  313. X
  314. X/*
  315. X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
  316. X *                    sees the transition; this value may be changed
  317. X *                    as necessary before each call to lflash_DTR(),
  318. X * but, generally, a constant value will do.
  319. X */
  320. Xlong DCE_DTR_low_msec = 500;
  321. X
  322. X/*
  323. X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
  324. X *                     DCE may be expected to be ready to be commanded
  325. X */
  326. Xlong DCE_DTR_high_msec = 1000L;
  327. X
  328. X/*
  329. X * DCE_write_pace_msec - milliseconds to pause between each character
  330. X *                       sent to the DCE (zero if streaming I/O is
  331. X *                       permitted); this value may be changed as
  332. X * necessary before each call to lwrite(), but, generally, a constant
  333. X * value will do.  Note that this value is used to feed a value to Nap(),
  334. X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
  335. X * and .050 seconds on XENIX/86.
  336. X */
  337. Xlong DCE_write_pace_msec = 10;
  338. X
  339. X/*
  340. X * DCE_name     - short name for DCE
  341. X * DCE_revision - revision number for this module
  342. X */
  343. Xchar *DCE_name = "Telebit T3000";
  344. Xchar *DCE_revision = "x1.10";
  345. X
  346. X/*
  347. X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
  348. X *                    and readying it for dial in access
  349. X *                    (BXXX mask); use a value of zero if the speed
  350. X *                    specified by the invoker is to be used.
  351. X * This value is useful for DCEs such as the early Hayes 2400
  352. X * which are so unfortunately compatible with their 1200 predecessor
  353. X * that they refuse to answer at 2400 baud unless you last spoke to
  354. X * them at that rate. For such bad boys, use B2400 below.
  355. X */
  356. Xint DCE_hangup_CBAUD = 0;
  357. X/* int DCE_hangup_CBAUD = B2400; */
  358. X
  359. X/*
  360. X * DCE_results - a table of DCE response strings and a token
  361. X *               code for each; when you call lread() or lread_ignore(),
  362. X *               if the read routine detects one of the strings,
  363. X * the appropriate code is returned.  If no string matches, then
  364. X * lread()/lread_ignore examines the DCE result string for a
  365. X * numeric value; if one is found, the numeric value or'd with
  366. X * 0x40000000 is returned (in this way, e.g., you can read "modem
  367. X * S registers").  If nothing agrees with this search, lread()
  368. X * will abort the program with RC_FAIL|RCE_TIMOUT, lread_ignore()
  369. X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
  370. X * This module is the only consumer  of the codes, although they
  371. X * are decoded by gendial.c's _lread()
  372. X */
  373. X
  374. X/* flag bits */
  375. X#define rfConnect        0x00800000
  376. X#define rfMASK            0x0000FFFF    /* mask off rfBits */
  377. X
  378. X/* unique codes */
  379. X#define rOk                0
  380. X#define rNoCarrier        1
  381. X#define rError            2
  382. X#define rNoDialTone     3
  383. X#define rBusy            4
  384. X#define rNoAnswer        5
  385. X#define rRring            6
  386. X#define rDialing        7
  387. X#define rConnect300        (   300 | rfConnect)
  388. X#define rConnect1200    (  1200 | rfConnect)
  389. X#define rConnect2400    (  1200 | rfConnect)
  390. X#define rConnect9600    (  9600 | rfConnect)
  391. X#define rConnect19200    ( 19200 | rfConnect)
  392. X#define rConnect38400    ( 38400 | rfConnect)
  393. X
  394. XDCE_RESULT DCE_results[] =
  395. X{
  396. X    { "OK",                        rOk,            },
  397. X    { "NO CARRIER",                rNoCarrier,        },
  398. X    { "ERROR",                    rError            },
  399. X    { "NO DIALTONE",            rNoDialTone,    },
  400. X    { "BUSY",                    rBusy            },
  401. X    { "NO ANSWER",                rNoAnswer        },
  402. X    { "DIALING",                rDialing        },
  403. X    { "RRING",                    rRring            },
  404. X    { "CONNECT 300",            rConnect300        },
  405. X    { "CONNECT 1200",            rConnect1200    },
  406. X    { "CONNECT 2400",            rConnect2400    },
  407. X    { "CONNECT 9600",            rConnect9600    },
  408. X    { "CONNECT 19200",            rConnect19200    },
  409. X    { "CONNECT 38400",            rConnect38400    },
  410. X    { (char *)0,                -1                }        /* end table */
  411. X};
  412. X
  413. X#include "tbit.sync.h"
  414. X
  415. X/*+-------------------------------------------------------------------------
  416. X    DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
  417. X
  418. X  DCE dependent function must validate baud rates supported by DCE
  419. X  returns baud rate in struct termio c_cflag fashion
  420. X  or terminates program with error
  421. X--------------------------------------------------------------------------*/
  422. Xint
  423. XDCE_baud_to_CBAUD(baud)
  424. Xunsigned int baud;
  425. X{
  426. X    switch(baud)
  427. X    {
  428. X        case 110:  return(B110);
  429. X        case 300:  return(B300);
  430. X        case 1200: return(B1200);
  431. X        case 2400: return(B2400);
  432. X        case 9600: return(B9600);
  433. X
  434. X#if defined(B19200)
  435. X        case 19200: return(B19200);
  436. X#else
  437. X#ifdef EXTA
  438. X        case 19200: return(EXTA);
  439. X#endif
  440. X#endif
  441. X
  442. X#if defined(B38400)
  443. X        case 38400: return(B38400);
  444. X#else
  445. X#ifdef EXTB
  446. X        case 38400: return(EXTB);
  447. X#endif
  448. X#endif
  449. X
  450. X    }
  451. X    myexit(RC_FAIL | RCE_SPEED);
  452. X#if defined(OPTIMIZE) || defined(__OPTIMIZE__)    /* don't complain */
  453. X    return(0);    /* keep gcc from complaining about no rtn at end */
  454. X#endif
  455. X}    /* end of DCE_baud_to_CBAUD */
  456. X
  457. X/*+-------------------------------------------------------------------------
  458. X    init_T3000() - init T3000 from scratch, assuming nothing
  459. X
  460. X    reset to factory defaults, then set
  461. X    E0          no local echo in command mode
  462. X    &C1         DCD follows carrier
  463. X    &D2         disconnect on DTR loss
  464. X    M0          speaker off
  465. X    Q2          generate reult codes only for originating use
  466. X    V1          verbal result codes
  467. X    X12         fullest result code set
  468. X    S0=1        answer on first ring
  469. X    S2=255        escape to unusual value
  470. X    S11=50      50 msec DTMF timing
  471. X    S45=0       disable remote access
  472. X    S48=1       all 8 bits are significant
  473. X    S50=0       use automatic connect speed determination
  474. X    S51=252     set serial port baud rate automatically (no typeahead)
  475. X    S58=2       DTE uses CTS/RTS flow control.
  476. X    S61=0       send BREAK (rather than go to command mode)
  477. X    S62=25      BREAK duration 250 msec (default is 150)
  478. X    S63=0       send BREAK in sequence
  479. X    S64=1       ignore characters sent by DTE while answering
  480. X    S66=0       don't lock interface speed, just go with the flow.
  481. X    S69=0       omit XON/XOFF flow control
  482. X    S68=255     DCE uses whatever flow control DTE uses
  483. X    S111=255    accept any protocol
  484. X
  485. XThe nvram is set to factory + E0 Q0 &C1 &D2 S51=252 
  486. X--------------------------------------------------------------------------*/
  487. Xvoid
  488. Xinit_T3000()
  489. X{
  490. Xregister itmp;
  491. Xint maxretry = 4;
  492. Xchar *init0="AT&F E0 Q0 &C1 &D2 S51=252 &w M0 Q2 V1 X12\r";
  493. Xchar *init1="ATS0=1 S2=255 S11=50 S45=0 S48=1 S50=0 \r";
  494. Xchar *init2="ATS58=2 S61=0 S62=25 S63=0 S62=25 S64=1 S66=0 S68=255 S111=255\r";
  495. X
  496. X    DEBUG(1,"--> initializing %s on ",DCE_name);
  497. X    DEBUG(1,"%s\n",dce_name);
  498. X
  499. X    lflash_DTR();
  500. X    sync_Telebit();
  501. X
  502. X    /*
  503. X     * set to factory default (bless them for this command)
  504. X     * and a few initial beachhead values
  505. X     */
  506. X    for(itmp = 0; itmp < maxretry; itmp++)
  507. X    {
  508. X        lwrite(init0);
  509. X        if(lread(5) == rOk)
  510. X            break;
  511. X    }
  512. X    if(itmp == maxretry)
  513. X    {
  514. X        DEBUG(1,"INIT FAILED (init0)\n",0);
  515. X        myexit(RC_FAIL | RCE_TIMOUT);
  516. X    }
  517. X
  518. X    /*
  519. X     * send initialization string 1
  520. X     */
  521. X    for(itmp = 0; itmp < maxretry; itmp++)
  522. X    {
  523. X        lwrite(init1);
  524. X        if(lread(5) == rOk)
  525. X            break;
  526. X    }
  527. X    if(itmp == maxretry)
  528. X    {
  529. X        DEBUG(1,"INIT FAILED (init1)\n",0);
  530. X        myexit(RC_FAIL | RCE_TIMOUT);
  531. X    }
  532. X
  533. X    /*
  534. X     * send initialization string 2
  535. X     */
  536. X    for(itmp = 0; itmp < maxretry; itmp++)
  537. X    {
  538. X        lwrite(init2);
  539. X        if(lread(5) == rOk)
  540. X            break;
  541. X    }
  542. X    if(itmp == maxretry)
  543. X    {
  544. X        DEBUG(1,"INIT FAILED (init2)\n",0);
  545. X        myexit(RC_FAIL | RCE_TIMOUT);
  546. X    }
  547. X
  548. X}    /* end of init_T3000 */
  549. X
  550. X/*+-------------------------------------------------------------------------
  551. X    DCE_hangup() - issue hangup command to DCE
  552. X
  553. XThis function should do whatever is necessary to ensure
  554. X1) any active connection is terminated
  555. X2) the DCE is ready to receive an incoming call if DTR is asserted
  556. X3) the DCE will not accept an incoming call if DTR is false
  557. X
  558. XThe function should return when done.
  559. X
  560. XAny necessary switch setting or other configuration necessary for this
  561. Xfunction to succeed should be documented at the top of the module.
  562. X--------------------------------------------------------------------------*/
  563. Xvoid
  564. XDCE_hangup()
  565. X{
  566. X    DEBUG(4,"--> hanging up %s\n",dce_name);
  567. X    init_T3000();
  568. X
  569. X}    /* end of DCE_hangup */
  570. X
  571. X/*+-------------------------------------------------------------------------
  572. X    DCE_dial(telno_str) - dial a remote DCE
  573. X
  574. XThis function should connect to the remote DCE and use any success
  575. Xindication to modify the tty baud rate if necessary before returning.
  576. X
  577. XUpon successful connection, return 0.
  578. X
  579. XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
  580. XRCE_XXX value from dialer.h.
  581. X
  582. Xlwrite() is used to write to the DCE.
  583. X
  584. Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
  585. Xfrom calling lread() will result automatically in the proper error
  586. Xtermination of the program.  Read timeouts from calling lread_ignore()
  587. Xreturn -1; you handle the execption here.
  588. X
  589. XAny necessary coding of phone numbers, switch settings or other
  590. Xconfiguration necessary for this function to succeed should be
  591. Xdocumented at the top of the module.
  592. X
  593. XT3000-specific comments:
  594. X S0=0        dont allow connect while dialing
  595. X S63=0       pass BREAK signal to remote modem in sequence
  596. X S64=0       abort dialing if characters sent by DTE
  597. X S66=1       lock the interface speed
  598. X--------------------------------------------------------------------------*/
  599. Xint
  600. XDCE_dial(telno_str)
  601. Xchar *telno_str;
  602. X{
  603. Xchar cmd[128];
  604. Xchar phone[50];
  605. Xint s111_set = 0;
  606. Xint timeout;
  607. Xint result;
  608. Xint rrings = 0;
  609. Xlong then;
  610. Xlong now;
  611. Xchar *cptr;
  612. Xchar *dialout_default = "AT S0=0 S7=40 S63=0 S64=0 S66=1\r";
  613. X#define MDVALID     "0123456789FfKkMmNnRrSsUuWwXxVv*#,!/()-"
  614. X#ifdef WHT
  615. X#define RRING_MAX 3
  616. X#else
  617. X#define RRING_MAX 6
  618. X#endif
  619. X
  620. X/* preliminary setup */
  621. X    translate("=,-,",telno_str);
  622. X    if(strspn(telno_str,MDVALID) != strlen(telno_str))
  623. X    {
  624. X        DEBUG(1,"phone number has invalid characters\n",0);
  625. X        return(RC_FAIL | RCE_PHNO);
  626. X    }
  627. X    if(decode_phone_number(telno_str,phone,sizeof(phone)))
  628. X    {
  629. X        DEBUG(1,"phone number too long\n",0);
  630. X        return(RC_FAIL | RCE_PHNO);
  631. X    }
  632. X
  633. X/* walk through dialer codes, doing custom setup */
  634. X    strcpy(cmd,"AT");
  635. X    cptr = cmd + strlen(cmd);
  636. X    if(dialer_codes['F' - 'A'])
  637. X    {
  638. X        DEBUG(5,"XON/XOFF FLOW CONTROL requested\n",0);
  639. X        strcat(cmd,"S69=2");
  640. X    }
  641. X    if(dialer_codes['K' - 'A'])
  642. X    {
  643. X        DEBUG(5,"KERMIT requested\n",0);
  644. X        strcat(cmd,"S111=10");
  645. X        s111_set++;
  646. X    }
  647. X    if(dialer_codes['X' - 'A'])
  648. X    {
  649. X        DEBUG(5,"XMODEM requested\n",0);
  650. X        strcat(cmd,"S111=20");
  651. X        s111_set++;
  652. X    }
  653. X    if(dialer_codes['U' - 'A'])
  654. X    {
  655. X        DEBUG(5,"UUCP requested\n",0);
  656. X        strcat(cmd,"S111=30");
  657. X        s111_set++;
  658. X    }
  659. X
  660. X    if(dialer_codes['V' - 'A'])
  661. X    {
  662. X        DEBUG(5,"V.32 requested\n",0);
  663. X        if(hiCBAUD != B9600)
  664. X        {
  665. X            DEBUG(1,"V.32 baud rate not 9600\n",0);
  666. X            return(RC_FAIL | RCE_SPEED);
  667. X        }
  668. X        if((dialer_codes['P' - 'A']) || s111_set)
  669. X        {
  670. X            DEBUG(1,"both PEP and V.32 requested\n",0);
  671. X            return(RC_FAIL | RCE_ARGS);
  672. X        }
  673. X        strcat(cmd,"S50=6");
  674. X    }
  675. X
  676. X    if((dialer_codes['P' - 'A']) || s111_set ||
  677. X        ((hiCBAUD >= B9600) && (!dialer_codes['V' - 'A'])))
  678. X    {
  679. X        if(hiCBAUD < B9600)
  680. X        {
  681. X            DEBUG(1,"baud rate not high enough for PEP\n",0);
  682. X            return(RC_FAIL | RCE_SPEED);
  683. X        }
  684. X        if(dialer_codes['P' - 'A'])
  685. X            DEBUG(5,"PEP requested\n",0);
  686. X        else
  687. X            DEBUG(5,"PEP inferred: speed >= 9600 and no V.32 requested\n",0);
  688. X
  689. X        dialer_codes['P' - 'A'] = 1;
  690. X        strcat(cmd,"S50=255");
  691. X    }
  692. X
  693. X    init_T3000();
  694. X
  695. X    DEBUG(2,"--> issuing default setup command\n",0);
  696. X    lwrite(dialout_default);
  697. X    if(lread(5) != rOk)
  698. X    {
  699. X        DEBUG(1,"default dialout setup failed\n",0);
  700. X        return(RC_FAIL | RCE_NULL);
  701. X    }
  702. X
  703. X/* issue the custom setup command */
  704. X    if(*cptr)
  705. X    {
  706. X        DEBUG(2,"--> issuing custom setup cmd\n",0);
  707. X        strcat(cmd,"\r");
  708. X        lwrite(cmd);
  709. X        if(lread(5) != rOk)
  710. X        {
  711. X            DEBUG(1,"custom modem setup failed\n",0);
  712. X            return(RC_FAIL | RCE_NULL);
  713. X        }
  714. X    }
  715. X
  716. X/*
  717. X * calculate a timeout for the connect
  718. X * allow a minimum of 40 seconds, but if V.32 or PEP, 90
  719. X * also if long distance (North American calculation here)
  720. X * make it 132 (S7 is calculated as timeout * .9)
  721. X */
  722. X    timeout = 40;
  723. X    if((phone[0] == '1') && (phone[0] != '0'))
  724. X        timeout = 132;
  725. X    if((timeout < 90) && (dialer_codes['V' - 'A'] || dialer_codes['P' - 'A']))
  726. X        timeout = 90;
  727. X    for(cptr = phone; cptr = strchr(cptr,','); cptr++)
  728. X        timeout += 2;    /* add extra time for pause characters */
  729. X    DEBUG(4,"wait for connect = %d seconds\n",timeout);
  730. X
  731. X    if(Debug > 8)
  732. X    {
  733. X        lwrite("AT&V\r");
  734. X        lread_ignore(40);
  735. X    }
  736. X
  737. X/* indicate non-root should not see DTE->DCE traffic */
  738. X    secure = 1;
  739. X
  740. X/*
  741. X * build and issue the actual dialing command
  742. X * if root, let him see number, otherwise just say "remote system"
  743. X */
  744. X    DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid)
  745. X        ? "remote system" : telno_str);
  746. X#ifdef WHT
  747. X    if(!strncmp(*gargv,"ECU",3))
  748. X        dialer_codes['S' - 'A'] = 1;
  749. X#endif
  750. X    sprintf(cmd,"ATM%dS7=%dDT%s\r",
  751. X        ((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
  752. X        (timeout * 9) / 10, phone);
  753. X
  754. X    /* cmd string can only be 80 characters including "AT" */
  755. X    if(strlen(cmd) > 80)
  756. X    {
  757. X        DEBUG(1,"phone number string too long\n",0);
  758. X        cleanup(RC_FAIL | RCE_PHNO);
  759. X    }
  760. X
  761. X    lwrite(cmd);
  762. X
  763. X/* indicate non-root can see DTE->DCE traffic */
  764. X    secure = 0;
  765. X
  766. X/* wait for connect */
  767. XWAIT_FOR_CONNECT:
  768. X    time(&then);
  769. X    result = lread(timeout);
  770. X    if(!(result & rfConnect))
  771. X    {
  772. X        switch(result & rfMASK)
  773. X        {
  774. X        case rNoCarrier:
  775. X            return(RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));
  776. X        case rNoDialTone:
  777. X            return(RC_FAIL | RCE_NOTONE);
  778. X        case rBusy:
  779. X            return(RC_FAIL | RCE_BUSY);
  780. X        case rNoAnswer:
  781. X            return(RC_FAIL | RCE_ANSWER);
  782. X        case rRring:
  783. X            if(rrings++ >= RRING_MAX)
  784. X                return(RC_FAIL | RCE_ANSWER);
  785. X        case rDialing:
  786. X            time(&now);
  787. X            if((timeout -= ((int)(then - now))) > 0)
  788. X                goto WAIT_FOR_CONNECT;
  789. X        case rError:
  790. X        default:
  791. X            return(RC_FAIL | RCE_NULL);
  792. X        }
  793. X    }
  794. X
  795. X    return(0);        /* succeeded */
  796. X
  797. X}    /* end of DCE_dial */
  798. X
  799. X/**********************************************************
  800. X*  You probably do not need to modify the code below here *
  801. X**********************************************************/
  802. X
  803. X/*+-------------------------------------------------------------------------
  804. X    DCE_abort(sig) - dial attempt aborted
  805. X
  806. X sig =  0 if non-signal abort (read timeout, most likely)
  807. X     != 0 if non-SIGALRM signal caught
  808. X
  809. X extern int dialing set  1 if dialing request was active,
  810. X                    else 0 if hangup request was active
  811. X
  812. XThis is a chance for the DCE-specific code to do anything it
  813. Xneeds to clean up after a failure.  Note that if a dialing
  814. Xcall fails, it is the responsibility of the higher-level
  815. Xprogram calling the dialer to call it again with a hangup request, so
  816. Xthis function is usually a no-op.
  817. X--------------------------------------------------------------------------*/
  818. Xvoid
  819. XDCE_abort(sig)
  820. Xint sig;
  821. X{
  822. X    DEBUG(10,"DCE_abort(%d);\n",sig);
  823. X}    /* end of DCE_abort */
  824. X
  825. X/*+-------------------------------------------------------------------------
  826. X    DCE_exit(exitcode) - "last chance for gas" in this incarnation
  827. X
  828. XThe independent portion of the dialer program calls this routine in
  829. Xlieu of exit() in every case except one (see DCE_argv_hook() below).
  830. XNormally, this function just passes it's argument to exit(), but
  831. Xany necessary post-processing can be done.  The function must,
  832. Xhowever, eventually call exit(exitcode);
  833. X--------------------------------------------------------------------------*/
  834. Xvoid
  835. XDCE_exit(exitcode)
  836. Xint exitcode;
  837. X{
  838. X    DEBUG(10,"DCE_exit(%d);\n",exitcode);
  839. X    exit(exitcode);
  840. X}    /* end of DCE_exit */
  841. X
  842. X/*+-------------------------------------------------------------------------
  843. X    DCE_argv_hook(argc,argv,optind,unrecognized_switches)
  844. X
  845. XThis hook gives DCE-specific code a chance to look over the entire
  846. Xcommand line, such as for -z Telebit processing.
  847. X
  848. Xargc andf argv are the same values passed to main(),
  849. X
  850. Xoptind is the value of optind at the end of normal getopt processing.
  851. X
  852. Xunrecognized_switches is the count of switches not handled by main().
  853. XSpecifically, -h and -x are standard switches.
  854. X
  855. XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
  856. Xany unrecognized switches, otherwise zero.  If you keep your nose clean
  857. Xthough, you can do anything you need to do here and exit the program.
  858. X
  859. XNote: only simple switches (with no argument) may be used with this
  860. Xfacility if the functrion is to return,' since main()'s getopt() will
  861. Xstop processing switches if it runs into an unrecognized switch with an
  862. Xargument.
  863. X
  864. XIf the function returns a non-zero value, then the value will be passed
  865. XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
  866. Xof the format expected by dialer program callers, with RC_FAIL set as a
  867. Xminimum.
  868. X--------------------------------------------------------------------------*/
  869. Xint
  870. XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
  871. Xint argc;
  872. Xchar **argv;
  873. Xint optind;
  874. Xint unrecognized_switches;
  875. X{
  876. X    if(unrecognized_switches)
  877. X        return(RC_FAIL | RCE_ARGS);
  878. X    return(0);
  879. X}    /* end of DCE_argv_hook */
  880. X
  881. X/* vi: set tabstop=4 shiftwidth=4: */
  882. SHAR_EOF
  883. chmod 0644 gendial/dceT3000.c ||
  884. echo 'restore of gendial/dceT3000.c failed'
  885. Wc_c="`wc -c < 'gendial/dceT3000.c'`"
  886. test 17548 -eq "$Wc_c" ||
  887.     echo 'gendial/dceT3000.c: original size 17548, current size' "$Wc_c"
  888. rm -f _shar_wnt_.tmp
  889. fi
  890. # ============= gendial/dceTBPlus.c ==============
  891. if test -f 'gendial/dceTBPlus.c' -a X"$1" != X"-c"; then
  892.     echo 'x - skipping gendial/dceTBPlus.c (File already exists)'
  893.     rm -f _shar_wnt_.tmp
  894. else
  895. > _shar_wnt_.tmp
  896. echo 'x - extracting gendial/dceTBPlus.c (Text)'
  897. sed 's/^X//' << 'SHAR_EOF' > 'gendial/dceTBPlus.c' &&
  898. X/* CHK=0xFF53 */
  899. X/* #define TRUSTING */        /* trust user has -z'd before use */
  900. X/*+-------------------------------------------------------------------------
  901. X    dceTBPlus.c - DCE-specific portion of generic SCO UUCP dialer
  902. X    Driver for Telebit Trailblazer Plus
  903. X    wht@n4hgf.Mt-Park.GA.US
  904. X--------------------------------------------------------------------------*/
  905. X/*+:EDITS:*/
  906. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  907. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  908. X/*:02-10-1992-00:27-wht@n4hgf-improved sync_Telebit */
  909. X/*:02-02-1992-18:01-root@n4hgf-proper ordering of DCE_result entries */
  910. X/*:01-26-1992-15:30-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
  911. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  912. X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
  913. X/*:11-29-1990-18:31-r@n4hgf-revision/1st releasable */
  914. X/*:07-20-1990-00:10-wht@n4hgf-creation */
  915. X
  916. X#include "dialer.h"
  917. X
  918. X/*
  919. X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
  920. X *                    sees the transition; this value may be changed
  921. X *                    as necessary before each call to lflash_DTR(),
  922. X * but, generally, a constant value will do.
  923. X */
  924. Xlong DCE_DTR_low_msec = 500;
  925. X
  926. X/*
  927. X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
  928. X *                     DCE may be expected to be ready to be commanded
  929. X */
  930. Xlong DCE_DTR_high_msec = 500;
  931. X
  932. X/*
  933. X * DCE_write_pace_msec - milliseconds to pause between each character
  934. X *                       sent to the DCE (zero if streaming I/O is
  935. X *                       permitted); this value may be changed as
  936. X * necessary before each call to lwrite(), but, generally, a constant
  937. X * value will do.  Note that this value is used to feed a value to Nap(),
  938. X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
  939. X * and .050 seconds on XENIX/86.
  940. X */
  941. Xlong DCE_write_pace_msec = 10;
  942. X
  943. X/*
  944. X * DCE_name     - short name for DCE
  945. X * DCE_revision - revision number for this module
  946. X */
  947. Xchar *DCE_name = "Telebit Trailblazer Plus";
  948. Xchar *DCE_revision = "1.30";
  949. X
  950. X/*
  951. X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
  952. X *                    and readying it for dial in access
  953. X *                    (BXXX mask); use a value of zero if the speed
  954. X *                    specified by the invoker is to be used.
  955. X * This value is useful for DCEs such as the early Hayes 2400
  956. X * which are so unfortunately compatible with their 1200 predecessor
  957. X * that they refuse to answer at 2400 baud unless you last spoke to
  958. X * them at that rate. For such bad boys, use B2400 below.
  959. X */
  960. Xint DCE_hangup_CBAUD = 0;
  961. X/* int DCE_hangup_CBAUD = B2400; */
  962. X
  963. X/*
  964. X * DCE_results - a table of DCE response strings and a token
  965. X *               code for each; when you call lread() or lread_ignore(),
  966. X *               if the read routine detects one of the strings,
  967. X * the appropriate code is returned.  If no string matches, then
  968. X * lread()/lread_ignore examines the DCE result string for a
  969. X * numeric value; if one is found, the numeric value or'd with
  970. X * 0x40000000 is returned (in this way, e.g., you can read "modem
  971. X * S registers").  If nothing agrees with this search, lread()
  972. X * will abort the program with RC|FAIL|RCE_TIMOUT, lread_ignore()
  973. X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
  974. X * This module is the only consumer  of the codes, although they
  975. X * are decoded by gendial.c's _lread().
  976. X *
  977. X * If one possible result is an "early substring" of another, like
  978. X * "CONNECT" is of "CONNECT 1200", then put such results later in the
  979. X * table than the larger result.
  980. X *
  981. X */
  982. X
  983. X/* flag bits */
  984. X#define rfConnect        0x00800000
  985. X#define rfREL            0x00400000
  986. X#define rfFAST            0x00200000
  987. X#define rfMASK            0x0000FFFF    /* mask off rfBits */
  988. X
  989. X/* unique codes */
  990. X#define rOk                0
  991. X#define rNoCarrier        1
  992. X#define rError            2
  993. X#define rNoDialTone     3
  994. X#define rBusy            4
  995. X#define rNoAnswer        5
  996. X#define rRring            6
  997. X#define rConnect300        (  300  | rfConnect)
  998. X#define rConnect1200    ( 1200  | rfConnect)
  999. X#define rConnect2400    ( 2400  | rfConnect)
  1000. X#define rConnect300R    (  300  | rfConnect | rfREL)
  1001. X#define rConnect1200R    ( 1200  | rfConnect | rfREL)
  1002. X#define rConnect2400R    ( 2400  | rfConnect | rfREL)
  1003. X#define rConnectFASTK    (19200  | rfConnect | rfFAST)
  1004. X#define rConnectFASTX    (19200  | rfConnect | rfFAST)
  1005. X#define rConnectFASTU    (19200  | rfConnect | rfFAST)
  1006. X#define rConnectFAST    (19200  | rfConnect | rfFAST)
  1007. X
  1008. XDCE_RESULT DCE_results[] =
  1009. X{
  1010. X    { "OK",                        rOk,            },
  1011. X    { "NO CARRIER",                rNoCarrier,        },
  1012. X    { "ERROR",                    rError            },
  1013. X    { "NO DIALTONE",            rNoDialTone,    },
  1014. X    { "BUSY",                    rBusy            },
  1015. X    { "NO ANSWER",                rNoAnswer        },
  1016. X    { "RRING",                    rRring            },
  1017. X    { "CONNECT 300/REL",        rConnect300R    },
  1018. X    { "CONNECT 1200/REL",        rConnect1200R    },
  1019. X    { "CONNECT 2400/REL",        rConnect2400R    },
  1020. X    { "CONNECT 300",            rConnect300        },
  1021. X    { "CONNECT 1200",            rConnect1200    },
  1022. X    { "CONNECT 2400",            rConnect2400    },
  1023. X    { "CONNECT FAST/KERM",        rConnectFASTK    },
  1024. X    { "CONNECT FAST/XMDM",        rConnectFASTX    },
  1025. X    { "CONNECT FAST/UUCP",        rConnectFASTU    },
  1026. X    { "CONNECT FAST",            rConnectFAST    },
  1027. X    { (char *)0,                -1                }        /* end table */
  1028. X};
  1029. X
  1030. X#include "tbit.sync.h"
  1031. X
  1032. X/*+-------------------------------------------------------------------------
  1033. X    DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
  1034. X
  1035. X  DCE dependent function must validate baud rates supported by DCE
  1036. X  returns baud rate in struct termio c_cflag fashion
  1037. X  or terminates program with error
  1038. X--------------------------------------------------------------------------*/
  1039. Xint
  1040. XDCE_baud_to_CBAUD(baud)
  1041. Xunsigned int baud;
  1042. X{
  1043. X    switch(baud)
  1044. X    {
  1045. X        case 110:  return(B110);
  1046. X        case 300:  return(B300);
  1047. X        case 1200: return(B1200);
  1048. X        case 2400: return(B2400);
  1049. X        case 9600: return(B9600);
  1050. X
  1051. X#if defined(B19200)
  1052. X        case 19200: return(B19200);
  1053. X#else
  1054. X#ifdef EXTA
  1055. X        case 19200: return(EXTA);
  1056. X#endif
  1057. X#endif
  1058. X
  1059. X#if defined(B38400)
  1060. X        case 38400: return(B38400);
  1061. X#else
  1062. X#ifdef EXTB
  1063. X        case 38400: return(EXTB);
  1064. X#endif
  1065. X#endif
  1066. X
  1067. X    }
  1068. X    myexit(RC_FAIL | RCE_SPEED);
  1069. X#if defined(OPTIMIZE) || defined(__OPTIMIZE__)    /* don't complain */
  1070. X    return(0);    /* keep gcc from complaining about no rtn at end */
  1071. X#endif
  1072. X}    /* end of DCE_baud_to_CBAUD */
  1073. X
  1074. X/*+-------------------------------------------------------------------------
  1075. X    init_TBPlus() - init TBPlus from scratch, assuming nothing
  1076. X
  1077. X    reset to factory defaults, then set
  1078. X    E0          no local echo in command mode
  1079. X    F1          no local echo in data transfer mode
  1080. X    M0          speaker off
  1081. X    Q4          generate reult codes, but not RING
  1082. X    V1          verbal result codes
  1083. X    X3          extended result codes
  1084. X    S0=1        answer on first ring
  1085. X    S2=255        escape to "unusual" value
  1086. X    S11=50      50 msec DTMF timing
  1087. X    S45=1       enable remote access
  1088. X    S48=1       all 8 bits are significant
  1089. X    S50=0       use automatic connect speed determination
  1090. X    S51=252     set serial port baud rate automatically (no typeahead)
  1091. X    S52=2       DTR low: drop connection and reset to nvram
  1092. X    S53=1       DCD signal follows remote carrier, DSR on when modem ready
  1093. X    S54=3       pass BREAK signal to remote modem
  1094. X    S55=0       respond to command escape sequence
  1095. X    S58=2       DTE uses CTS/RTS flow control.
  1096. X    S64=1       ignore characters sent by DTE while answering
  1097. X    S66=0       don't lock interface speed, just go with the flow.
  1098. X    S68=255     DCE uses whatever flow control DTE uses
  1099. X    S92=1       PEP tones at the end of answer sequence
  1100. X    S95=0       no MNP
  1101. X    S110=255    use data compression when the remote modem requests it.
  1102. X    S111=255    accept any protocol
  1103. X--------------------------------------------------------------------------*/
  1104. Xvoid
  1105. Xinit_TBPlus()
  1106. X{
  1107. Xregister itmp;
  1108. Xint maxretry = 4;
  1109. Xchar *init0 = "AT~&FE0F1M0Q4V1X3S52=2\r";
  1110. Xchar *init1 = "ATS0=1S2=255S11=50S45=1S48=1S50=0S51=252S53=1S54=3\r";
  1111. Xchar *init2 = "ATS55=0S58=2S64=1S66=0S68=255S92=1S95=0S110=255S111=255\r";
  1112. X
  1113. X    DEBUG(1,"--> initializing %s\n",dce_name);
  1114. X    lflash_DTR();
  1115. X    sync_Telebit();
  1116. X
  1117. X    /*
  1118. X     * set to factory default (bless them for this command)
  1119. X     * and a few initial beachhead values
  1120. X     */
  1121. X    for(itmp = 0; itmp < maxretry; itmp++)
  1122. X    {
  1123. X        lwrite(init0);
  1124. X        if(lread(5) == rOk)
  1125. X            break;
  1126. X    }
  1127. X    if(itmp == maxretry)
  1128. X    {
  1129. X        DEBUG(1,"INIT FAILED (init0)\n",0);
  1130. X        myexit(RC_FAIL | RCE_TIMOUT);
  1131. X    }
  1132. X
  1133. X    /*
  1134. X     * send initialization string 1
  1135. X     */
  1136. X    for(itmp = 0; itmp < maxretry; itmp++)
  1137. X    {
  1138. X        lwrite(init1);
  1139. X        if(lread(5) == rOk)
  1140. X            break;
  1141. X    }
  1142. X    if(itmp == maxretry)
  1143. X    {
  1144. X        DEBUG(1,"INIT FAILED (init1)\n",0);
  1145. X        myexit(RC_FAIL | RCE_TIMOUT);
  1146. X    }
  1147. X
  1148. X    /*
  1149. X     * send initialization string 2
  1150. X     */
  1151. X    for(itmp = 0; itmp < maxretry; itmp++)
  1152. X    {
  1153. X        lwrite(init2);
  1154. X        if(lread(5) == rOk)
  1155. X            break;
  1156. X    }
  1157. X    if(itmp == maxretry)
  1158. X    {
  1159. X        DEBUG(1,"INIT FAILED (init2)\n",0);
  1160. X        myexit(RC_FAIL | RCE_TIMOUT);
  1161. X    }
  1162. X
  1163. X}    /* end of init_TBPlus */
  1164. X
  1165. X/*+-------------------------------------------------------------------------
  1166. X    DCE_hangup() - issue hangup command to DCE
  1167. X
  1168. XThis function should do whatever is necessary to ensure
  1169. X1) any active connection is terminated
  1170. X2) the DCE is ready to receive an incoming call if DTR is asserted
  1171. X3) the DCE will not accept an incoming call if DTR is false
  1172. X
  1173. XThe function should return when done.
  1174. X
  1175. XAny necessary switch setting or other configuration necessary for this
  1176. Xfunction to succeed should be documented at the top of the module.
  1177. X--------------------------------------------------------------------------*/
  1178. Xvoid
  1179. XDCE_hangup()
  1180. X{
  1181. X    DEBUG(1,"--> reseting %s\n",dce_name);
  1182. X#ifdef TRUSTING
  1183. X    lflash_DTR();
  1184. X    lwrite("ATZ\r");
  1185. X    (void)lread_ignore(1);
  1186. X#else /* !TRUSTING */
  1187. X    init_TBPlus();
  1188. X#endif
  1189. X
  1190. X}    /* end of DCE_hangup */
  1191. X
  1192. X/*+-------------------------------------------------------------------------
  1193. X    DCE_dial(telno_str) - dial a remote DCE
  1194. X
  1195. XThis function should connect to the remote DCE and use any success
  1196. Xindication to modify the tty baud rate if necessary before returning.
  1197. X
  1198. XUpon successful connection, return 0.
  1199. X
  1200. XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
  1201. XRCE_XXX value from dialer.h.
  1202. X
  1203. Xlwrite() is used to write to the DCE.
  1204. X
  1205. Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
  1206. Xfrom calling lread() will result automatically in the proper error
  1207. Xtermination of the program.  Read timeouts from calling lread_ignore()
  1208. Xreturn -1; you handle the execption here.
  1209. X
  1210. XAny necessary coding of phone numbers, switch settings or other
  1211. Xconfiguration necessary for this function to succeed should be
  1212. Xdocumented at the top of the module.
  1213. X
  1214. XTelebit Plus-specific comments:
  1215. X S0=0        dont allow connect while dialing
  1216. X S54=3       pass BREAK signal to remote modem
  1217. X S64=0       abort dialing if characters sent by DTE
  1218. X S66=1       lock the interface speed
  1219. X S110=0      disable data compression unless requested otherwise
  1220. X--------------------------------------------------------------------------*/
  1221. Xint
  1222. XDCE_dial(telno_str)
  1223. Xchar *telno_str;
  1224. X{
  1225. Xchar cmd[128];
  1226. Xchar phone[50];
  1227. Xint s111_set = 0;
  1228. Xint timeout;
  1229. Xint result;
  1230. Xint rrings = 0;
  1231. Xlong then;
  1232. Xlong now;
  1233. Xchar *cptr;
  1234. Xchar *dialout_default = "ATS0=0S7=40S54=3S64=0S66=1S110=0\r";
  1235. X#define MDVALID     "0123456789CcEeFfKkMmNnPpRrSsUuWwXx*#,!/()-"
  1236. X
  1237. X/* preliminary setup */
  1238. X    translate("=,-,",telno_str);
  1239. X    if(strspn(telno_str,MDVALID) != strlen(telno_str))
  1240. X    {
  1241. X        DEBUG(1,"phone number has invalid characters\n",0);
  1242. X        return(RC_FAIL | RCE_PHNO);
  1243. X    }
  1244. X    if(decode_phone_number(telno_str,phone,sizeof(phone)))
  1245. X    {
  1246. X        DEBUG(1,"phone number too long\n",0);
  1247. X        return(RC_FAIL | RCE_PHNO);
  1248. X    }
  1249. X
  1250. X/* walk through dialer codes, doing custom setup */
  1251. X    strcpy(cmd,"AT");
  1252. X    cptr = cmd + strlen(cmd);
  1253. X    if(dialer_codes['C' - 'A'])
  1254. X    {
  1255. X        DEBUG(5,"COMPRESSION requested\n",0);
  1256. X        strcat(cmd,"S110=1");
  1257. X    }
  1258. X    if(dialer_codes['E' - 'A'])
  1259. X    {
  1260. X        DEBUG(5,"ECHO SUPPRESSION requested\n",0);
  1261. X        strcat(cmd,"S121=1");
  1262. X    }
  1263. X    if(dialer_codes['F' - 'A'])
  1264. X    {
  1265. X        DEBUG(5,"XON/XOFF FLOW CONTROL requested\n",0);
  1266. X        strcat(cmd,"S58=3");
  1267. X    }
  1268. X    if(dialer_codes['K' - 'A'])
  1269. X    {
  1270. X        DEBUG(5,"KERMIT requested\n",0);
  1271. X        strcat(cmd,"S111=10");
  1272. X        s111_set++;
  1273. X    }
  1274. X    if(dialer_codes['X' - 'A'])
  1275. X    {
  1276. X        DEBUG(5,"XMODEM requested\n",0);
  1277. X        strcat(cmd,"S111=20");
  1278. X        s111_set++;
  1279. X    }
  1280. X    if(dialer_codes['U' - 'A'])
  1281. X    {
  1282. X        DEBUG(5,"UUCP requested\n",0);
  1283. X        strcat(cmd,"S111=30");
  1284. X        s111_set++;
  1285. X    }
  1286. X    if(dialer_codes['M' - 'A'])
  1287. X    {
  1288. X        DEBUG(5,"MNP requested\n",0);
  1289. X        strcat(cmd,"S95=1");
  1290. X    }
  1291. X
  1292. X    if((dialer_codes['P' - 'A']) || s111_set || (hiCBAUD >= B9600))
  1293. X    {
  1294. X        if(hiCBAUD < B9600)
  1295. X        {
  1296. X            DEBUG(1,"baud rate not high enough for PEP\n",0);
  1297. X            return(RC_FAIL | RCE_SPEED);
  1298. X        }
  1299. X        if(dialer_codes['P' - 'A'])
  1300. X            DEBUG(5,"PEP requested\n",0);
  1301. X        else
  1302. X            DEBUG(5,"PEP inferred: speed >= 9600\n",0);
  1303. X
  1304. X        dialer_codes['P' - 'A'] = 1;
  1305. X        strcat(cmd,"S50=255");
  1306. X    }
  1307. X
  1308. X
  1309. X    DEBUG(6,"--> issuing default setup command\n",0);
  1310. X    sync_Telebit();
  1311. X    lwrite(dialout_default);
  1312. X    if(lread(5) != rOk)
  1313. X    {
  1314. X        DEBUG(1,"default dialout setup failed\n",0);
  1315. X        return(RC_FAIL | RCE_NULL);
  1316. X    }
  1317. X
  1318. X/* issue the custom setup command */
  1319. X    if(*cptr)
  1320. X    {
  1321. X        DEBUG(5,"--> issuing custom setup cmd\n",0);
  1322. X        strcat(cmd,"\r");
  1323. X        sync_Telebit();
  1324. X        lwrite(cmd);
  1325. X        if(lread(5) != rOk)
  1326. X        {
  1327. X            DEBUG(1,"custom modem setup failed\n",0);
  1328. X            return(RC_FAIL | RCE_NULL);
  1329. X        }
  1330. X    }
  1331. X
  1332. X/*
  1333. X * calculate a timeout for the connect
  1334. X * allow a minimum of 40 seconds, but if PEP, 90
  1335. X * also if long distance (North American calculation here)
  1336. X * make it 132 (S7 is calculated as timeout * .9)
  1337. X */
  1338. X    timeout = 40;
  1339. X    if((phone[0] == '1') && (phone[0] != '0'))
  1340. X        timeout = 132;
  1341. X    if((timeout < 90) && dialer_codes['P' - 'A'])
  1342. X        timeout = 90;
  1343. X    for(cptr = phone; cptr = strchr(cptr,','); cptr++)
  1344. X        timeout += 2;    /* add extra time for pause characters */
  1345. X    DEBUG(6,"wait for connect = %d seconds\n",timeout);
  1346. X
  1347. X/* indicate non-root should not see DTE->DCE traffic */
  1348. X    secure = 1;
  1349. X
  1350. X/*
  1351. X * build and issue the actual dialing command
  1352. X * if root, let him see number, otherwise just say "remote system"
  1353. X */
  1354. X    DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid)
  1355. X        ? "remote system" : telno_str);
  1356. X#ifdef WHT
  1357. X    if(!strncmp(*gargv,"ECU",3))
  1358. X        dialer_codes['S' - 'A'] = 1;
  1359. X#endif
  1360. X    sprintf(cmd,"ATM%dS7=%dDT%s\r",
  1361. X        ((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
  1362. X        (timeout * 9) / 10,phone);
  1363. X
  1364. X    /* cmd string can only be 80 characters including "AT" */
  1365. X    if(strlen(cmd) > 80)
  1366. X    {
  1367. X        DEBUG(1,"phone number string too long\n",0);
  1368. X        cleanup(RC_FAIL | RCE_PHNO);
  1369. X    }
  1370. X
  1371. X    sync_Telebit();
  1372. X    lwrite(cmd);
  1373. X
  1374. X/* indicate non-root can see DTE->DCE traffic */
  1375. X    secure = 0;
  1376. X
  1377. X/* wait for connect */
  1378. XWAIT_FOR_CONNECT:
  1379. X    time(&then);
  1380. X    result = lread(timeout);
  1381. X    if(!(result & rfConnect))
  1382. X    {
  1383. X        switch(result & rfMASK)
  1384. X        {
  1385. X        case rNoCarrier:
  1386. X            return(RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));
  1387. X        case rNoDialTone:
  1388. X            return(RC_FAIL | RCE_NOTONE);
  1389. X        case rBusy:
  1390. X            return(RC_FAIL | RCE_BUSY);
  1391. X        case rNoAnswer:
  1392. X            return(RC_FAIL | RCE_ANSWER);
  1393. X        case rRring:
  1394. X            if(rrings++ > 7)
  1395. X                return(RC_FAIL | RCE_ANSWER);
  1396. X            time(&now);
  1397. X            if((timeout -= ((int)(then - now))) > 0)
  1398. X                goto WAIT_FOR_CONNECT;
  1399. X        case rError:
  1400. X        default:
  1401. X            return(RC_FAIL | RCE_NULL);
  1402. X        }
  1403. X    }
  1404. X
  1405. X    return(0);        /* succeeded */
  1406. X
  1407. X}    /* end of DCE_dial */
  1408. X
  1409. X/**********************************************************
  1410. X*  You probably do not need to modify the code below here *
  1411. X**********************************************************/
  1412. X
  1413. X/*+-------------------------------------------------------------------------
  1414. X    DCE_abort(sig) - dial attempt aborted
  1415. X
  1416. X sig =  0 if non-signal abort (read timeout, most likely)
  1417. X     != 0 if non-SIGALRM signal caught
  1418. X
  1419. X extern int dialing set  1 if dialing request was active,
  1420. X                    else 0 if hangup request was active
  1421. X
  1422. XThis is a chance for the DCE-specific code to do anything it
  1423. Xneeds to cl,ean up after a failure.  Note that if a dialing
  1424. Xcall fails, it is the responsibility of the higher-level
  1425. Xprogram calling the dialer to call it again with a hangup request, so
  1426. Xthis function is usually a no-op.
  1427. X--------------------------------------------------------------------------*/
  1428. Xvoid
  1429. XDCE_abort(sig)
  1430. Xint sig;
  1431. X{
  1432. X    DEBUG(10,"DCE_abort(%d);\n",sig);
  1433. X}    /* end of DCE_abort */
  1434. X
  1435. X/*+-------------------------------------------------------------------------
  1436. X    DCE_exit(exitcode) - "last chance for gas" in this incarnation
  1437. X
  1438. XThe independent portion of the dialer program calls this routine in
  1439. Xlieu of exit() in every case except one (see DCE_argv_hook() below).
  1440. XNormally, this function just passes it's argument to exit(), but
  1441. Xany necessary post-processing can be done.  The function must,
  1442. Xhowever, eventually call exit(exitcode);
  1443. X--------------------------------------------------------------------------*/
  1444. Xvoid
  1445. XDCE_exit(exitcode)
  1446. Xint exitcode;
  1447. X{
  1448. X    DEBUG(10,"DCE_exit(%d);\n",exitcode);
  1449. X    exit(exitcode);
  1450. X}    /* end of DCE_exit */
  1451. X
  1452. X/*+-------------------------------------------------------------------------
  1453. X    DCE_argv_hook(argc,argv,optind,unrecognized_switches)
  1454. X
  1455. XThis hook gives DCE-specific code a chance to look over the entire
  1456. Xcommand line, such as for -z Telebit processing.
  1457. X
  1458. Xargc andf argv are the same values passed to main(),
  1459. X
  1460. Xoptind is the value of optind at the end of normal getopt processing.
  1461. X
  1462. Xunrecognized_switches is the count of switches not handled by main().
  1463. XSpecifically, -h and -x are standard switches.
  1464. X
  1465. XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
  1466. Xany unrecognized switches, otherwise zero.  If you keep your nose clean
  1467. Xthough, you can do anything you need to do here and exit the program.
  1468. X
  1469. XNote: only simple switches (with no argument) may be used with this
  1470. Xfacility if the functrion is to return,' since main()'s getopt() will
  1471. Xstop processing switches if it runs into an unrecognized switch with an
  1472. Xargument.
  1473. X
  1474. XIf the function returns a non-zero value, then the value will be passed
  1475. XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
  1476. Xof the format expected by dialer program callers, with RC_FAIL set as a
  1477. Xminimum.
  1478. X--------------------------------------------------------------------------*/
  1479. Xint
  1480. XDCE_argv_hook(argc,argv,optind,unrecognized_switches)
  1481. Xint argc;
  1482. Xchar **argv;
  1483. Xint optind;
  1484. Xint unrecognized_switches;
  1485. X{
  1486. X    if(unrecognized_switches)
  1487. X        return(RC_FAIL | RCE_ARGS);
  1488. X    return(0);
  1489. X}    /* end of DCE_argv_hook */
  1490. X
  1491. X/* vi: set tabstop=4 shiftwidth=4: */
  1492. SHAR_EOF
  1493. chmod 0644 gendial/dceTBPlus.c ||
  1494. echo 'restore of gendial/dceTBPlus.c failed'
  1495. Wc_c="`wc -c < 'gendial/dceTBPlus.c'`"
  1496. test 17953 -eq "$Wc_c" ||
  1497.     echo 'gendial/dceTBPlus.c: original size 17953, current size' "$Wc_c"
  1498. rm -f _shar_wnt_.tmp
  1499. fi
  1500. # ============= gendial/dceUSR24.c ==============
  1501. if test -f 'gendial/dceUSR24.c' -a X"$1" != X"-c"; then
  1502.     echo 'x - skipping gendial/dceUSR24.c (File already exists)'
  1503.     rm -f _shar_wnt_.tmp
  1504. else
  1505. > _shar_wnt_.tmp
  1506. echo 'x - extracting gendial/dceUSR24.c (Text)'
  1507. sed 's/^X//' << 'SHAR_EOF' > 'gendial/dceUSR24.c' &&
  1508. X/*+------------------------------------------------------------------------- dceUSR24.c - DCE-specific portion of generic SCO UUCP dialer
  1509. X    Driver for USR Courier 2400
  1510. X    wht@n4hgf.Mt-Park.GA.US
  1511. X
  1512. X Necessary DCE switch setting or other configuration:
  1513. X   enable onhook upon loss of DTR
  1514. X
  1515. XThis dialer does not use the X6 quick dial feature, nor voice detection.
  1516. XQuick dial tone recognition often fqails due to the telco granting
  1517. Xdial tone ahead of the actual time it is ready to accept dialing.
  1518. XVoice recognition fails when dialing 0+ with a credit card, as in "Thank
  1519. Xyou for using ATT" - CLICK - "VOICE".
  1520. X
  1521. X--------------------------------------------------------------------------*/
  1522. X/*+:EDITS:*/
  1523. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1524. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1525. X/*:02-02-1992-18:01-root@n4hgf-proper ordering of DCE_result entries */
  1526. X/*:01-26-1992-15:30-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
  1527. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  1528. X/*:07-25-1991-04:34-wht@n4hgf-add naps around writes */
  1529. X/*:04-16-1991-18:18-wht@n4hgf-creation from template */
  1530. X
  1531. X#include "dialer.h"
  1532. X
  1533. X/*
  1534. X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
  1535. X *                    sees the transition; this value may be changed
  1536. X *                    as necessary before each call to lflash_DTR(),
  1537. X * but, generally, a constant value will do.
  1538. X */
  1539. Xlong DCE_DTR_low_msec = 500L;
  1540. X
  1541. X/*
  1542. X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
  1543. X *                     DCE may be expected to be ready to be commanded
  1544. X */
  1545. Xlong DCE_DTR_high_msec = 1000L;
  1546. X
  1547. X/*
  1548. X * DCE_write_pace_msec - milliseconds to pause between each character
  1549. X *                       sent to the DCE (zero if streaming I/O is
  1550. X *                       permitted); this value may be changed as
  1551. X * necessary before each call to lwrite(), but, generally, a constant
  1552. X * value will do.  Note that this value is used to feed a value to Nap(),
  1553. X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
  1554. X * and .050 seconds on XENIX/86.
  1555. X */
  1556. Xlong DCE_write_pace_msec = 50;
  1557. X
  1558. X/*
  1559. X * DCE_name     - short name for DCE
  1560. X * DCE_revision - revision number for this module
  1561. X */
  1562. Xchar *DCE_name = "USR Courier 2400";
  1563. Xchar *DCE_revision = "1.21";
  1564. X
  1565. X/*
  1566. X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
  1567. X *                    and readying it for dial in access
  1568. X *                    (BXXX mask); use a value of zero if the speed
  1569. X *                    specified by the invoker is to be used.
  1570. X * This value is useful for DCEs such as the early Hayes 2400
  1571. X * which are so unfortunately compatible with their 1200 predecessor
  1572. X * that they refuse to answer at 2400 baud unless you last spoke to
  1573. X * them at that rate. For such bad boys, use B2400 below.
  1574. X */
  1575. Xint DCE_hangup_CBAUD = B2400;
  1576. X
  1577. X/*
  1578. X * DCE_results - a table of DCE response strings and a token
  1579. X *               code for each; when you call lread() or lread_ignore(),
  1580. X *               if the read routine detects one of the strings,
  1581. X * the appropriate code is returned.  If no string matches, then
  1582. X * lread()/lread_ignore examines the DCE result string for a
  1583. X * numeric value; if one is found, the numeric value or'd with
  1584. X * 0x4000 is returned (in this way, e.g., you can read "modem
  1585. X * S registers."  If nothing agrees with this search, lread()
  1586. X * will abort the program with RC|FAIL|RCE_TIMOUT, lread_ignore()
  1587. X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
  1588. X * This module is the only consumer  of the codes, although they
  1589. X * are decoded by gendial.c's _lread()
  1590. X *
  1591. X * If one possible result is an "early substring" of another, like
  1592. X * "CONNECT" is of "CONNECT 1200", then put such results later in the
  1593. X * table than the larger result.
  1594. X *
  1595. X */
  1596. X#define rfConnect        0x00400000
  1597. X#define rfMASK            0x000000FF
  1598. X
  1599. X#define rOk                0
  1600. X#define rNoCarrier        1
  1601. X#define rError            2
  1602. X#define rNoDialTone        3
  1603. X#define rBusy            4
  1604. X#define rNoAnswer        5
  1605. X#define rVoice            6
  1606. X#define rConnect300        (7 | rfConnect)
  1607. X#define rConnect1200    (8 | rfConnect)
  1608. X#define rConnect2400    (9 | rfConnect)
  1609. X
  1610. XDCE_RESULT DCE_results[] =
  1611. X{
  1612. X    { "OK",                        rOk,            },
  1613. X    { "NO CARRIER",                rNoCarrier,        },
  1614. X    { "ERROR",                    rError            },
  1615. X    { "NO DIALTONE",            rNoDialTone,    },
  1616. X    { "BUSY",                    rBusy            },
  1617. X    { "NO ANSWER",                rNoAnswer        },
  1618. X    { "VOICE",                    rVoice            },
  1619. X    { "CONNECT 1200",            rConnect1200    },
  1620. X    { "CONNECT 2400",            rConnect2400    },
  1621. X    { "CONNECT",                rConnect300        },
  1622. X    { (char *)0,                -1                }        /* end table */
  1623. X};
  1624. X
  1625. X/*+-------------------------------------------------------------------------
  1626. X    DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
  1627. X
  1628. X  DCE dependent function must validate baud rates supported by DCE
  1629. X  returns baud rate in struct termio c_cflag fashion
  1630. X  or terminates program with error
  1631. X--------------------------------------------------------------------------*/
  1632. Xint
  1633. XDCE_baud_to_CBAUD(baud)
  1634. Xunsigned int baud;
  1635. X{
  1636. X    switch(baud)
  1637. X    {
  1638. X        case 50:   return(B50);        /* delete the ones you dont handle */
  1639. X        case 75:   return(B75);
  1640. X        case 110:  return(B110);
  1641. X        case 134:  return(B134);
  1642. X        case 150:  return(B150);
  1643. X        case 300:  return(B300);
  1644. X        case 1200: return(B1200);
  1645. X        case 2400: return(B2400);
  1646. X        case 4800: return(B4800);
  1647. X        case 9600: return(B9600);
  1648. X
  1649. X#if defined(B19200)
  1650. X        case 19200: return(B19200);
  1651. X#else
  1652. X#ifdef EXTA
  1653. X        case 19200: return(EXTA);
  1654. X#endif
  1655. X#endif
  1656. X
  1657. X#if defined(B38400)
  1658. X        case 38400: return(B38400);
  1659. X#else
  1660. X#ifdef EXTB
  1661. X        case 38400: return(EXTB);
  1662. X#endif
  1663. X#endif
  1664. X
  1665. X    }
  1666. X    myexit(RC_FAIL | RCE_SPEED);
  1667. X#if defined(OPTIMIZE) || defined(__OPTIMIZE__)
  1668. X    return(0);    /* I wish this wasn't necessary to avoid warnings */
  1669. X#endif
  1670. X}    /* end of DCE_baud_to_CBAUD */
  1671. X
  1672. X/*+-------------------------------------------------------------------------
  1673. X    DCE_hangup() - issue hangup command to DCE
  1674. X
  1675. XThis function should do whatever is necessary to ensure
  1676. X1) any active connection is terminated
  1677. X2) the DCE is ready to receive an incoming call if DTR is asserted
  1678. X3) the DCE will not accept an incoming call if DTR is false
  1679. X
  1680. XThe function should return when done.
  1681. X
  1682. XYou must set any switches necessary to make modem hang up on loss of DTR
  1683. X--------------------------------------------------------------------------*/
  1684. Xvoid
  1685. XDCE_hangup()
  1686. X{
  1687. Xint itmp;
  1688. Xint maxretry = 4;
  1689. X
  1690. X    DEBUG(1,"--> hanging up %s\n",dce_name);
  1691. X    lflash_DTR();
  1692. X
  1693. X    /*
  1694. X     * reset modem completely
  1695. X     */
  1696. X    lwrite("AAAAAATZ\r");
  1697. X    Nap(2000L);
  1698. X    lflush();
  1699. X
  1700. X    /*
  1701. X     * set up modem
  1702. X     */
  1703. X    for(itmp = 0; itmp < maxretry; itmp++)
  1704. X    {
  1705. X        lwrite("ATS0=1M0Q0V1X3\r");
  1706. X        if(lread(5) == rOk)
  1707. X            break;
  1708. X        Nap(500L);
  1709. X    }
  1710. X    if(itmp == maxretry)
  1711. X    {
  1712. X        DEBUG(1,"INIT FAILED (init0)\n",0);
  1713. X        myexit(RC_FAIL | RCE_TIMOUT);
  1714. X    }
  1715. X
  1716. X    /*
  1717. X     * shut up - no result codes
  1718. X     */
  1719. X    Nap(500L);
  1720. X    lwrite("ATQ1\r");
  1721. X    Nap(750L);
  1722. X
  1723. X}    /* end of DCE_hangup */
  1724. X
  1725. X/*+-------------------------------------------------------------------------
  1726. X    DCE_dial(telno_str) - dial a remote DCE
  1727. X
  1728. XThis function should connect to the remote DCE and use any success
  1729. Xindication to modify the tty baud rate if necessary before returning.
  1730. X
  1731. XUpon successful connection, return 0.
  1732. X
  1733. XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
  1734. XRCE_XXX value from dialer.h.
  1735. X
  1736. Xlwrite() is used to write to the DCE.
  1737. X
  1738. Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
  1739. Xfrom calling lread() will result automatically in the proper error
  1740. Xtermination of the program.  Read timeouts from calling lread_ignore()
  1741. Xreturn -1; you handle the execption here.
  1742. X
  1743. XAny necessary coding of phone numbers, switch settings or other
  1744. Xconfiguration necessary for this function to succeed should be
  1745. Xdocumented at the top of the module.
  1746. X--------------------------------------------------------------------------*/
  1747. Xint
  1748. XDCE_dial(telno_str)
  1749. Xchar *telno_str;
  1750. X{
  1751. Xchar cmd[128];
  1752. Xchar phone[50];
  1753. Xint timeout;
  1754. Xint result;
  1755. Xchar *cptr;
  1756. Xchar *dialout_default = "ATS0=0S7=40Q0M0V1E0X3\r";
  1757. X#define MDVALID     "0123456789NnSs*#,!/()-"
  1758. Xint itmp;
  1759. Xint maxretry = 4;
  1760. X
  1761. X/* if root, let him see number, otherwise just say "remote system" */
  1762. X    DEBUG(1,"DIALING %s\n", (uid) ? "remote system" : telno_str);
  1763. X    translate("=,-,",telno_str);
  1764. X    if(strspn(telno_str,MDVALID) != strlen(telno_str))
  1765. X    {
  1766. X        DEBUG(1,"phone number has invalid characters\n",0);
  1767. X        return(RC_FAIL | RCE_PHNO);
  1768. X    }
  1769. X    if(decode_phone_number(telno_str,phone,sizeof(phone)))
  1770. X    {
  1771. X        DEBUG(1,"phone number too long\n",0);
  1772. X        return(RC_FAIL | RCE_PHNO);
  1773. X    }
  1774. X
  1775. X    /*
  1776. X     * wake up modem
  1777. X     */
  1778. X    DEBUG(6,"--> waking up modem\n",0);
  1779. X    for(itmp = 0; itmp < maxretry; itmp++)
  1780. X    {
  1781. X        lwrite(dialout_default);
  1782. X        if(lread_ignore(5) == rOk)
  1783. X            break;
  1784. X        lflash_DTR();
  1785. X    }
  1786. X    if(itmp == maxretry)
  1787. X    {
  1788. X        DEBUG(1,"DIAL INIT FAILED\n",0);
  1789. X        myexit(RC_FAIL | RCE_TIMOUT);
  1790. X    }
  1791. X
  1792. X    /*
  1793. X     * calculate a timeout for the connect
  1794. X     * allow a minimum of 40 seconds
  1795. X     * if long distance (North American calculation here)
  1796. X     * make it 132 (S7 is calculated as timeout * .95)
  1797. X     */
  1798. X    timeout = 40;
  1799. X    if((phone[0] == '1') && (phone[0] != '0'))
  1800. X        timeout = 132;
  1801. X    if((timeout < 90) && (dialer_codes['V' - 'A'] || dialer_codes['P' - 'A']))
  1802. X        timeout = 90;
  1803. X    for(cptr = phone; cptr = strchr(cptr,','); cptr++)
  1804. X        timeout += 2;    /* add extra time for pause characters */
  1805. X    DEBUG(6,"wait for connect = %d seconds\n",timeout);
  1806. X
  1807. X    /*
  1808. X     * do custom setup here to conserve 40 char max cmd for telno_str
  1809. X     */
  1810. X#ifdef WHT
  1811. X    if(!strncmp(*gargv,"ECU",3))
  1812. X        dialer_codes['S' - 'A'] = 1;
  1813. X#endif
  1814. X    sprintf(cmd,"ATM%dS7=%dS11=40T\r",
  1815. X        ((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
  1816. X        (int)((timeout * 95L) / 100L));
  1817. X    DEBUG(6,"--> setting speaker, DTMF dialing and wait for carrier time\n",0);
  1818. X    Nap(200L);
  1819. X    for(itmp = 0; itmp < maxretry; itmp++)
  1820. X    {
  1821. X        lwrite(cmd);
  1822. X        if(lread(5) == rOk)
  1823. X            break;
  1824. X        Nap(200L);
  1825. X    }
  1826. X    if(itmp == maxretry)
  1827. X    {
  1828. X        DEBUG(1,"DIAL INIT FAILED\n",0);
  1829. X        myexit(RC_FAIL | RCE_TIMOUT);
  1830. X    }
  1831. X
  1832. X
  1833. X/* indicate non-root should not see DTE->DCE traffic */
  1834. X    secure = 1;
  1835. X
  1836. X/*
  1837. X * build and issue the actual dialing command
  1838. X * if root, let him see number, otherwise just say "remote system"
  1839. X */
  1840. X    DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid)
  1841. X        ? "remote system" : telno_str);
  1842. X    sprintf(cmd,"ATD%s\r",phone);
  1843. X
  1844. X    /* cmd string can only be 40 characters including "AT" */
  1845. X    if(strlen(cmd) > 40)
  1846. X    {
  1847. X        DEBUG(1,"phone number string too long\n",0);
  1848. X        cleanup(RC_FAIL | RCE_PHNO);
  1849. X    }
  1850. X    Nap(200L);
  1851. X    lwrite(cmd);
  1852. X
  1853. X/* indicate non-root can see DTE->DCE traffic */
  1854. X    secure = 0;
  1855. X
  1856. X/* wait for connect */
  1857. X    result = lread(timeout);
  1858. X    if(!(result & rfConnect))
  1859. X    {
  1860. X        switch(result & rfMASK)
  1861. X        {
  1862. X        case rNoCarrier:
  1863. X            return(RC_FAIL | RCE_NOCARR);
  1864. X        case rVoice:    /* if you get voice, certainly wrong number */
  1865. X        case rNoDialTone:
  1866. X            return(RC_FAIL | RCE_NOTONE);
  1867. X        case rBusy:
  1868. X            return(RC_FAIL | RCE_BUSY);
  1869. X        case rNoAnswer:
  1870. X            return(RC_FAIL | RCE_ANSWER);
  1871. X        case rError:
  1872. X        default:
  1873. X            return(RC_FAIL | RCE_NULL);
  1874. X        }
  1875. X    }
  1876. X
  1877. X/* indicate non-root can see DTE->DCE traffic */
  1878. X    secure = 0;
  1879. X    return(0);        /* succeeded */
  1880. X
  1881. X}    /* end of DCE_dial */
  1882. X
  1883. X/**********************************************************
  1884. X*  You probably do not need to modify the code below here *
  1885. X**********************************************************/
  1886. X
  1887. X/*+-------------------------------------------------------------------------
  1888. X    DCE_abort(sig) - dial attempt aborted
  1889. X
  1890. X sig =  0 if non-signal abort (read timeout, most likely)
  1891. X     != 0 if non-SIGALRM signal caught
  1892. X
  1893. X extern int dialing set  1 if dialing request was active,
  1894. X                    else 0 if hangup request was active
  1895. X
  1896. XThis is a chance for the DCE-specific code to do anything it
  1897. Xneeds to cl,ean up after a failure.  Note that if a dialing
  1898. Xcall fails, it is the responsibility of the higher-level
  1899. Xprogram calling the dialer to call it again with a hangup request, so
  1900. SHAR_EOF
  1901. true || echo 'restore of gendial/dceUSR24.c failed'
  1902. fi
  1903. echo 'End of ecu320 part 29'
  1904. echo 'File gendial/dceUSR24.c is continued in part 30'
  1905. echo 30 > _shar_seq_.tmp
  1906. exit 0
  1907.  
  1908. exit 0 # Just in case...
  1909.