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

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