home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc095.zip / ckudia.c < prev    next >
C/C++ Source or Header  |  1989-08-31  |  38KB  |  1,189 lines

  1. char *dialv = "Dial Command, V2.0(013) 29 Aug 89";
  2.  
  3. /*  C K U D I A     --  Dialing program for connection to remote system */
  4.  
  5. /*
  6.  Original author: Herm Fischer (HFISCHER@USC-ECLB).
  7.  Contributed to Columbia University for inclusion in C-Kermit.
  8.  Copyright (C) 1985, Herman Fischer, 16400 Ventura Blvd, Encino CA 91436.
  9.  Permission is granted to any individual or institution to use, copy, or
  10.  redistribute this software so long as it is not sold for profit, provided this
  11.  copyright notice is retained.
  12.  
  13.  Os9/68k and Microcom modem support by Bob Larson (Blarson@ecla.usc.edu)
  14.  
  15.  ------
  16.  
  17.  This module should work under all versions of Unix.  It calls externally
  18.  defined system-depended functions for i/o, but depends upon the existence
  19.  of various modem control functions.
  20.  
  21.  This module, and the supporting routines in the ckutio.c module, assume
  22.  that the computer and modem properly utilize the following data communi-
  23.  cations signals (that means one should prepare the modem to use, not
  24.  circumvent, these signals):
  25.  
  26.      Data Terminal Ready:  This signal is asserted by the computer
  27.      when Kermit is about to ask the modem to dial a call, and is
  28.      removed when Kermit wishes to have the modem hang up a call.
  29.      The signal is asserted both while Kermit is asking the modem
  30.      to dial a specific number, and after connection, while Kermit
  31.      is in a data exchange mode.
  32.  
  33.      Carrier detect:  This signal must be asserted by the modem when
  34.      a carrier is detected from a remote modem on a communications
  35.      circuit.  It must be removed by the modem when the circuit
  36.      disconnects or is hung up.     (Carrier detect is ignored while
  37.      Kermit is asking the modem to dial the call, because there is
  38.      no consistant usage of this signal during the dialing phase
  39.      among different modem manufacturers.)
  40.  
  41. */
  42.  
  43. /*
  44.  * Modifications:
  45.  *
  46.  *    21-Jul-85    Fixed failure returns hanging on no carrier signal
  47.  *            Requires tthang change too (ckutio.c revision)
  48.  *                            -- Herm Fischer
  49.  *
  50.  *    28-Jun-85    Fixed bug with defaulting the modem-failure message
  51.  *            in lbuf.
  52.  *                            -- Dan Schullman
  53.  *
  54.  *    27-Jun-85    Merged in code from Joe Orost at Berkeley for
  55.  *            supporting the US Robotics modem, which included
  56.  *            changing the single characters in MDMINF into
  57.  *            multi-character strings and modifying waitFor.
  58.  *                            -- Dan Schullman
  59.  *
  60.  *    26-Jun-85    Allow interrupts to be used to abort dialing,
  61.  *            and ring the bell when a connection is made.
  62.  *            Reorganized some of the failure paths to use the
  63.  *            same code, and now close the line on failures.
  64.  *            Allow use of stored numbers with the DF100 and
  65.  *            DF200 modems.  Handlers now declared after the
  66.  *            call to setjmp.
  67.  *                            -- Dan Schullman
  68.  *
  69.  *    24-May-85    DF03, DF100-series, DF200-series, and "unknown" modem
  70.  *            support added.    Also restructured the various data
  71.  *            tables, fixed some bugs related to missing data and
  72.  *            missing case labels, and modified the failure message
  73.  *            to display the "reason" given by the modem.
  74.  *                            -- Dan Schullman
  75.  *    16-Mar-87    Support for the ATT7300 UNIX PC internal modem was
  76.  *            added.
  77.  *                            -- Richard E. Hill
  78.  *
  79.  *    21-Feb-88    Os9/68k and microcom modem support.
  80.  *                            -- Bob Larson
  81.  *
  82.  *    14-Mar-88    Rewrite code for ATT7300 (here and in ckutio.c)
  83.  *            Avoids dial(3c) with it's LCK files, hangs up line
  84.  *            correctly, enables user interrupts and timeouts,
  85.  *            turns on/off the system getty() login procedure.
  86.  *            Correct Hayes command sequence at little.
  87.  *            Procedures: attdial, atthang, ongetty, offgetty.
  88.  *            Parts adapted from work of Richard E. Hill and
  89.  *            Kevin O'Gorman.
  90.  *                            -- Joe R. Doupnik
  91.  *
  92.  * 13-Jan-89 Add IBM/Siemens/Rolm CBX dialing support.  - F. da Cruz
  93.  *
  94.  *    29-Aug-89    Added support for AT&T 2212C, 2224B, 2224CEO, and
  95.  *            2296A switched-network modems in AT&T mode, and
  96.  *            for the AT&T Digital Terminal Data Module (DTDM).
  97.  *                            -- Eric F. Jones
  98.  */
  99.  
  100. /*
  101.  * To add support for another modem, do the following:
  102.  *
  103.  *    Define a modem number symbol (n_XXX) for it, keeping the list
  104.  *    in alphabetical and numerical order, and renumbering the values
  105.  *    as necessary.
  106.  *
  107.  *    Create a MDMINF structure for it, again keeping the list alphabetical
  108.  *    for sanity's sake.
  109.  *
  110.  *    Add the address of the MDMINF structure to the ptrtab array, again
  111.  *    in alphabetical and numerical order.
  112.  *
  113.  *    Add the "user visible" modem name and corresponding modem number to
  114.  *    the mdmtab array, again in alphabetical order.
  115.  *
  116.  *    Read through the code and add modem-specific sections as necessary.
  117.  */
  118.  
  119. /*
  120.  * The intent of the "unknown" modem is hopefully to allow KERMIT to support
  121.  * unknown modems by having the user type the entire autodial sequence
  122.  * (possibly including control characters, etc.) as the "phone number".
  123.  * The only reason that the CONNECT command cannot be used to do this is
  124.  * that a remote line cannot normally be opened unless carrier is present.
  125.  *
  126.  * The protocol and other characteristics of this modem are unknown, with
  127.  * some "reasonable" values being chosen for some of them.  The only way to
  128.  * detect if a connection is made is to look for carrier present.
  129.  *
  130.  * SUPPORT IS CURRENTLY ONLY PARTIALLY SKETCHED OUT FOR THIS.  ALSO, IT
  131.  * SHOULD PERHAPS BE HANDLED MUCH EARLIER, SIMPLY READING USER INPUT AND
  132.  * SENDING IT TO THE MODEM AND ECHOING MODEM RESPONSES BACK TO THE USER,
  133.  * ALL THE TIME LOOKING FOR CARRIER.  OF COURSE, THE PROBLEM THEN BECOMES
  134.  * ONE OF ALLOWING THE USER TO CANCEL THE DIALING.  WE COULD CHOOSE SOME
  135.  * PHRASE THAT WOULD PRESUMABLY NEVER BE A PART OF A VALID AUTODIAL SEQUENCE
  136.  * (E.G., "QUIT" and "quit"). -- DS
  137.  */
  138. #include "ckcdeb.h"
  139. #include <stdio.h>
  140. #include <ctype.h>
  141. #include <signal.h>
  142. #include "ckcker.h"
  143. #include "ckucmd.h"
  144.  
  145. #ifndef ZILOG
  146. #include <setjmp.h>            /* Longjumps */
  147. #else
  148. #include <setret.h>
  149. #endif
  150.  
  151. #ifdef OS2
  152. #define SIGALRM SIGUSR1
  153. void alarm( unsigned );
  154. #endif
  155.  
  156. extern int flow, local, mdmtyp, quiet, speed, parity, seslog, ttyfd;
  157. extern char ttname[], sesfil[];
  158.  
  159. #define MDMINF    struct mdminf
  160.  
  161. MDMINF        /* structure for modem-specific information */
  162.     {
  163.     int        dial_time;    /* time modem allows for dialing (secs) */
  164.     char    *pause_chars;    /* character(s) to tell modem to pause */
  165.     int        pause_time;    /* time associated with pause chars (secs) */
  166.     char    *wake_str;    /* string to wakeup modem & put in cmd mode */
  167.     int        wake_rate;    /* delay between wake_str characters (msecs) */
  168.     char    *wake_prompt;    /* string prompt after wake_str */
  169.     char    *dmode_str;    /* string to put modem in dialing mode */
  170.     char    *dmode_prompt;    /* string prompt for dialing mode */
  171.     char    *dial_str;    /* dialing string, with "%s" for number */
  172.     int        dial_rate;    /* delay between dialing characters (msecs) */
  173.     };
  174.  
  175. /*
  176.  * Define symbolic modem numbers.
  177.  *
  178.  * The numbers MUST correspond to the ordering of entries
  179.  * within the ptrtab array, and start at one (1).
  180.  *
  181.  * It is assumed that there are relatively few of these
  182.  * values, and that the high(er) bytes of the value may
  183.  * be used for modem-specific mode information.
  184.  *
  185.  * REMEMBER that only the first eight characters of these
  186.  * names are guaranteed to be unique.
  187.  */
  188.  
  189. #define        n_ATTDTDM     1
  190. #define        n_ATTMODEM     2
  191. #define        n_CERMETEK     3
  192. #define        n_DF03         4
  193. #define        n_DF100         5
  194. #define        n_DF200         6
  195. #define        n_GDC         7
  196. #define        n_HAYES         8
  197. #define        n_PENRIL     9
  198. #define        n_RACAL        10
  199. #define        n_UNKNOWN    11
  200. #define        n_USROBOT    12
  201. #define        n_VENTEL    13
  202. #define        n_CONCORD    14
  203. #define        n_ATTUPC    15    /* aka Unix PC and ATT7300 */
  204. #define        n_ROLM          16      /* Rolm CBX */
  205. #define        n_MICROCOM    17
  206.  
  207. /*
  208.  * Declare modem "variant" numbers for any of the above for which it is
  209.  * necessary to note various operational modes, using the second byte
  210.  * of a modem number.
  211.  *
  212.  * It is assumed that such modem modes share the same modem-specific
  213.  * information (see MDMINF structure) but may differ in some of the actions
  214.  * that are performed.
  215.  */
  216. #define        n_HAYESNV    ( n_HAYES + ( 1<<8 ) )
  217.  
  218. /*
  219.  * Declare structures containing modem-specific information.
  220.  *
  221.  * REMEMBER that only the first SEVEN characters of these
  222.  * names are guaranteed to be unique.
  223.  */
  224.  
  225. static
  226. MDMINF ATTMODEM =    /* information for AT&T switched-network modems */
  227.             /* "Number" following "dial" can include: p's and
  228.              * t's to indicate pulse or tone (default) dialing,
  229.              * + for wait for dial tone, , for pause, r for
  230.              * last number dialed, and, except for 2224B, some
  231.              * comma-delimited options like o12=y, before number.
  232.  
  233.  * "Important" options for the modems:
  234.  *
  235.  *    All:        Except for 2224B, enable option 12 for "transparent
  236.  *            data," o12=y.  If a computer port used for both
  237.  *            incoming and outgoing calls is connected to the
  238.  *            modem, disable "enter interactive mode on carriage
  239.  *            return," EICR.  The Kermit "dial" command can
  240.  *            function with EIA leads standard, EIAS.
  241.  *
  242.  *    2212C:        Internal hardware switches at their default
  243.  *            positions (four rockers down away from numbers)
  244.  *            unless EICR is not wanted (rocker down at the 4).
  245.  *            For EIAS, rocker down at the 1.
  246.  *
  247.  *    2224B:        Front-panel switch position 1 must be up (at the 1,
  248.  *            closed).  Disable EICR with position 2 down.
  249.  *            For EIAS, position 4 down.
  250.  *            All switches on the back panel down.
  251.  *
  252.  *    2224CEO:    All front-panel switches down except either 5 or 6.
  253.  *            Enable interactive flow control with o16=y.
  254.  *            Select normal asynchronous mode with o34=0 (zero).
  255.  *            Disable EICR with position 3 up.  For EIAS, 1 up.
  256.  *            Reset the modem after changing switches.
  257.  *
  258.  *    2296A:        If option 00 (zeros) is present, use o00=0.
  259.  *            Enable interactive flow control with o16=y.
  260.  *            Select normal asynchronous mode with o34=0 (zero).
  261.  *            Enable modem-port flow control (if available) with
  262.  *             o42=y.  Enable asynchronous operation with o50=y.
  263.  *             Disable EICR with o69=n.  For EIAS, o66=n, using
  264.  *             front panel.
  265.  */
  266.     {
  267.     20,            /* dial_time */
  268.     ",",        /* pause_chars */
  269.     2,            /* pause_time */
  270.     "+",        /* wake_str */
  271.     0,            /* wake_rate */
  272.     "",            /* wake_prompt */
  273.     "",            /* dmode_str */
  274.     "",            /* dmode_prompt */
  275.     "at%s\r",        /* dial_str */
  276.     0            /* dial_rate */
  277.     };
  278.  
  279. static
  280. MDMINF ATTDTDM =    /* information for AT&T Digital Terminal Data Module
  281.  *            For dialing: KYBD switch down, others usually up. */
  282.     {
  283.     5,            /* dial_time */
  284.     "",            /* pause_chars */
  285.     0,            /* pause_time */
  286.     "",            /* wake_str */
  287.     0,            /* wake_rate */
  288.     "",            /* wake_prompt */
  289.     "",            /* dmode_str */
  290.     "",            /* dmode_prompt */
  291.     "%s\r",        /* dial_str */        /* not used */
  292.     0            /* dial_rate */
  293.     };
  294.  
  295. static
  296. MDMINF CERMETEK =    /* information for "Cermetek Info-Mate 212 A" modem */
  297.     {
  298.     20,            /* dial_time */
  299.     "BbPpTt",        /* pause_chars */
  300.     0,            /* pause_time */    /** unknown -- DS **/
  301.     "  XY\016R\r",    /* wake_str */
  302.     200,        /* wake_rate */
  303.     "",            /* wake_prompt */
  304.     "",            /* dmode_str */
  305.     NULL,        /* dmode_prompt */
  306.     "\016D '%s'\r",    /* dial_str */
  307.     200            /* dial_rate */
  308.     };
  309.  
  310. static
  311. MDMINF DF03 =        /* information for "DEC DF03-AC" modem */
  312.     {
  313.     27,            /* dial_time */
  314.     "=",        /* pause_chars */    /* wait for second dial tone */
  315.     15,            /* pause_time */
  316.     "\001\002",        /* wake_str */
  317.     0,            /* wake_rate */
  318.     "",            /* wake_prompt */
  319.     "",            /* dmode_str */
  320.     NULL,        /* dmode_prompt */
  321.     "%s",        /* dial_str */
  322.     0            /* dial_rate */
  323.     };
  324.  
  325. static
  326. MDMINF DF100 =        /* information for "DEC DF100-series" modem */
  327.             /*
  328.              * The telephone "number" can include "P"s and/or "T"s
  329.              * within it to indicate that subsequent digits are
  330.              * to be dialed using pulse or tone dialing.  The
  331.              * modem defaults to pulse dialing.  You may modify
  332.              * the dial string below to explicitly default all
  333.              * dialing to pulse or tone, but doing so prevents
  334.              * the use of phone numbers that you may have stored
  335.              * in the modem's memory.
  336.              */
  337.     {
  338.     30,            /* dial_time */
  339.     "=",        /* pause_chars */    /* wait for second dial tone */
  340.     15,            /* pause_time */
  341.     "\001",        /* wake_str */
  342.     0,            /* wake_rate */
  343.     "",            /* wake_prompt */
  344.     "",            /* dmode_str */
  345.     NULL,        /* dmode_prompt */
  346.     "%s#",        /* dial_str */
  347.     0            /* dial_rate */
  348.     };
  349.  
  350. static
  351. MDMINF DF200 =        /* information for "DEC DF200-series" modem */
  352.             /*
  353.              * The telephone "number" can include "P"s and/or "T"s
  354.              * within it to indicate that subsequent digits are
  355.              * to be dialed using pulse or tone dialing.  The
  356.              * modem defaults to pulse dialing.  You may modify
  357.              * the dial string below to explicitly default all
  358.              * dialing to pulse or tone, but doing so prevents
  359.              * the use of phone numbers that you may have stored
  360.              * in the modem's memory.
  361.              */
  362.     {
  363.     30,            /* dial_time */
  364.     "=W",        /* pause_chars */    /* =: second tone; W: 5 secs */
  365.     15,            /* pause_time */    /* worst case */
  366.     "\002",        /* wake_str */        /* allow stored number usage */
  367.     0,            /* wake_rate */
  368.     "",            /* wake_prompt */
  369.     "",            /* dmode_str */
  370.     NULL,        /* dmode_prompt */
  371.     "%s!",        /* dial_str */
  372.     0            /* dial_rate */
  373.     };
  374.  
  375. static
  376. MDMINF GDC =        /* information for "GeneralDataComm 212A/ED" modem */
  377.     {
  378.     32,            /* dial_time */
  379.     "%",        /* pause_chars */
  380.     3,            /* pause_time */
  381.     "\r\r",        /* wake_str */
  382.     500,        /* wake_rate */
  383.     "$",        /* wake_prompt */
  384.     "D\r",        /* dmode_str */
  385.     ":",        /* dmode_prompt */
  386.     "T%s\r",        /* dial_str */
  387.     0            /* dial_rate */
  388.     };
  389.  
  390. static
  391. MDMINF HAYES =        /* information for "Hayes" modem */
  392.     {
  393.     35,            /* dial_time */
  394.     ",",        /* pause_chars */
  395.     2,            /* pause_time */
  396.     "AT\r",        /* wake_str */
  397. /*** Note: Other wake_str's are possible here.  For Hayes 2400 that is to
  398. /*** be used for both in and out calls, AT&F&D3 might be best.  For out calls
  399. /*** only, maybe AT&F&D2.  See Hayes 2400 manual. ***/
  400.     0,            /* wake_rate */
  401.     "",            /* wake_prompt */
  402.     "",            /* dmode_str */
  403.     "",            /* dmode_prompt */
  404.     "ATD%s\r",        /* dial_str, note: user can supply D or T */
  405.     0            /* dial_rate */
  406.     };
  407.  
  408. static
  409. MDMINF PENRIL =        /* information for "Penril" modem */
  410.     {
  411.     50,            /* dial_time */
  412.     "",            /* pause_chars */    /** unknown -- HF **/
  413.     0,            /* pause_time */
  414.     "\r\r",        /* wake_str */
  415.     300,        /* wake_rate */
  416.     ">",        /* wake_prompt */
  417.     "k\r",        /* dmode_str */
  418.     ":",        /* dmode_prompt */
  419.     "%s\r",        /* dial_str */
  420.     0            /* dial_rate */
  421.     };
  422.  
  423. static
  424. MDMINF RACAL =        /* information for "Racal Vadic" modem */
  425.     {
  426.     35,            /* dial_time */
  427.     "Kk",        /* pause_chars */
  428.     5,            /* pause_time */
  429.     "\005\r",        /* wake_str */
  430.     50,            /* wake_rate */
  431.     "*",        /* wake_prompt */
  432.     "D\r",        /* dmode_str */
  433.     "?",        /* dmode_prompt */
  434.     "%s\r",        /* dial_str */
  435.     0            /* dial_rate */
  436.     };
  437.  
  438. static
  439. MDMINF UNKNOWN =    /* information for "Unknown" modem */
  440.     {
  441.     30,            /* dial_time */
  442.     "",            /* pause_chars */
  443.     0,            /* pause_time */
  444.     "",            /* wake_str */
  445.     0,            /* wake_rate */
  446.     "",            /* wake_prompt */
  447.     "",            /* dmode_str */
  448.     NULL,        /* dmode_prompt */
  449.     "%s\r",        /* dial_str */
  450.     0            /* dial_rate */
  451.     };
  452.  
  453. static
  454. MDMINF USROBOT =    /* information for "US Robotics 212A" modem */
  455.     {
  456.     30,            /* dial_time */
  457.     ",",        /* pause_chars */
  458.     2,            /* pause_time */
  459.     "ATS2=01\r",    /* wake_str */
  460.     0,            /* wake_rate */
  461.     "OK\r",        /* wake_prompt */
  462.     "",            /* dmode_str */
  463.     NULL,        /* dmode_prompt */
  464.     "ATTD%s\r",        /* dial_str */
  465.     0            /* dial_rate */
  466.     };
  467.  
  468. static
  469. MDMINF VENTEL =        /* information for "Ventel" modem */
  470.     {
  471.     20,            /* dial_time */
  472.     "%",        /* pause_chars */
  473.     5,            /* pause_time */
  474.     "\r\r\r",        /* wake_str */
  475.     300,        /* wake_rate */
  476.     "$",        /* wake_prompt */
  477.     "",            /* dmode_str */
  478.     NULL,        /* dmode_prompt */
  479.     "<K%s\r>",        /* dial_str */
  480.     0            /* dial_rate */
  481.     };
  482.  
  483. static
  484. MDMINF CONCORD =    /* Info for Condor CDS 220 2400b modem */
  485.     {
  486.     35,            /* dial_time */
  487.     ",",        /* pause_chars */
  488.     2,            /* pause_time */
  489.     "\r\r",        /* wake_str */
  490.     20,            /* wake_rate */
  491.     "CDS >",        /* wake_prompt */
  492.     "",            /* dmode_str */
  493.     NULL,        /* dmode_prompt */
  494.     "<D M%s\r>",    /* dial_str */
  495.     0            /* dial_rate */
  496.     };
  497.  
  498. static
  499. MDMINF ATTUPC = /* dummy information for "ATT7300/Unix PC" internal modem */
  500.     {
  501.     20,            /* dial_time */
  502.     "",            /* pause_chars */
  503.     0,            /* pause_time */
  504.     "",            /* wake_str */
  505.     0,            /* wake_rate */
  506.     "",            /* wake_prompt */
  507.     "",            /* dmode_str */
  508.     NULL,        /* dmode_prompt */
  509.     "%s\r",        /* dial_str */
  510.     0            /* dial_rate */
  511.     };
  512.  
  513. static
  514. MDMINF ROLM =        /* IBM / Siemens / Rolm 8000, 9000, 9751 CBX */
  515.     {
  516.     60,            /* dial_time */
  517.     "",            /* pause_chars */
  518.     0,            /* pause_time */
  519.     "\r\r",        /* wake_str */
  520.     5,            /* wake_rate */
  521.     "MODIFY?",            /* wake_prompt */
  522.     "",            /* dmode_str */
  523.     "",            /* dmode_prompt */
  524.     "CALL %s\r",    /* dial_str */
  525.     0            /* dial_rate */
  526.     };
  527.  
  528. static
  529. MDMINF MICROCOM =    /* information for "Microcom" modems in native mode */
  530.             /* (long answer only) */
  531.     {
  532.     35,            /* dial_time */
  533.     ",!@",        /* pause_chars (! and @ aren't pure pauses) */
  534.     3,            /* pause_time */
  535.     "\r",        /* wake_str */
  536.     100,        /* wake_rate */
  537.     "!",        /* wake_prompt */
  538.     "",            /* dmode_str */
  539.     NULL,        /* dmode_prompt */
  540.     "d%s\r",        /* dial_str */
  541.     0            /* dial_rate */
  542.     };
  543.  
  544. /*
  545.  * Declare table for converting modem numbers to information pointers.
  546.  *
  547.  * The entries MUST be in ascending order by modem number, without any
  548.  * "gaps" in the numbers, and starting from one (1).
  549.  *
  550.  * This table should NOT include entries for the "variant" modem numbers,
  551.  * since it is assumed that they share the same information as the normal
  552.  * value.
  553.  */
  554. static
  555. MDMINF *ptrtab[] =
  556.     {
  557.     &ATTDTDM,
  558.     &ATTMODEM,
  559.     &CERMETEK,
  560.     &DF03,
  561.     &DF100,
  562.     &DF200,
  563.     &GDC,
  564.     &HAYES,
  565.     &PENRIL,
  566.     &RACAL,
  567.     &UNKNOWN,
  568.     &USROBOT,
  569.     &VENTEL,
  570.     &CONCORD,
  571.     &ATTUPC,            /* ATT7300 internal modem, jrd*/
  572.     &ROLM,            /* Rolm CBX, fdc */
  573.     &MICROCOM,
  574.     };
  575.  
  576. /*
  577.  * Declare modem names and associated numbers for command parsing,
  578.  * and also for doing number-to-name translation.
  579.  *
  580.  * The entries MUST be in alphabetical order by modem name.
  581.  */
  582. struct keytab mdmtab[] =
  583.     {
  584.     "attdtdm",        n_ATTDTDM,    0,
  585.     "attmodem",        n_ATTMODEM,    0,
  586.     "att7300",        n_ATTUPC,    0,
  587.     "cermetek",        n_CERMETEK,    0,
  588.     "concord",        n_CONCORD,    0,
  589.     "df03-ac",        n_DF03,        0,
  590.     "df100-series",    n_DF100,    0,
  591.     "df200-series",    n_DF200,    0,
  592.     "direct",        0,        0,
  593.     "gendatacomm",    n_GDC,        0,
  594.     "hayes",        n_HAYES,    0,
  595.     "microcom",        n_MICROCOM,    0,
  596.     "penril",        n_PENRIL,    0,
  597.     "racalvadic",    n_RACAL,    0,
  598.     "rolm",        n_ROLM,        0,
  599.     "unknown",        n_UNKNOWN,    0,
  600.     "usrobotics-212a",    n_USROBOT,    0,
  601.     "ventel",        n_VENTEL,    0
  602.     };
  603.  
  604. int nmdm = (sizeof(mdmtab) / sizeof(struct keytab));    /* number of modems */
  605.  
  606. #define DIALING 4        /* for ttpkt parameter */
  607. #define CONNECT 5
  608.  
  609. #define CONNECTED 1        /* for completion status */
  610. #define FAILED      2
  611.  
  612. /*
  613.  * Failure reasons for use with the 'longjmp' exit.
  614.  */
  615. #define F_time        1    /* timeout */
  616. #define F_int        2    /* interrupt */
  617. #define F_modem        3    /* modem-detected failure */
  618. #define F_minit        4    /* cannot initialize modem */
  619.  
  620. static
  621. char *F_reason[5] = {        /* failure reasons for message */
  622.     "Unknown",    "Timeout", "Interrupt", "Modem", "Initialize" };
  623.  
  624. static int tries = 0;
  625.  
  626. #define LBUFL 100
  627. static char lbuf[LBUFL];
  628.  
  629. static jmp_buf sjbuf;
  630.  
  631. static SIGTYP (*savAlrm)();    /* for saving alarm handler */
  632. static SIGTYP (*savInt)();    /* for saving interrupt handler */
  633.  
  634. char *                    /* Copy a string of the */
  635. xcpy(to,from,len)            /* the given length. */
  636.   register char *to, *from;
  637.   register unsigned len; {
  638.     while (len--) *to++ = *from++;
  639. }
  640.  
  641. SIGTYP
  642. dialtime() {            /* timer interrupt handler */
  643. #ifdef OS2
  644.     alarmack();
  645. #endif
  646.     longjmp( sjbuf, F_time );
  647. }
  648.  
  649. SIGTYP
  650. dialint() {                /* user-interrupt handler */
  651. #ifdef OS2
  652.     alarmack();
  653. #endif
  654.     longjmp( sjbuf, F_int );
  655.     }
  656.  
  657. static
  658. ttolSlow(s,millisec) char *s; int millisec; {  /* output s-l-o-w-l-y */
  659.     for (; *s; s++) {
  660.     ttoc(*s);
  661.     msleep(millisec);
  662.     }
  663.     }
  664.  
  665. /*
  666.  * Wait for a string of characters.
  667.  *
  668.  * The characters are waited for individually, and other characters may
  669.  * be received "in between".  This merely guarantees that the characters
  670.  * ARE received, and in the order specified.
  671.  */
  672. static
  673. waitFor(s) char *s; {
  674.     CHAR c;
  675.     while ( c = *s++ )            /* while more characters remain... */
  676.     while ( ( ttinc(0) & 0177 ) != c ) /* wait for the character */
  677.         ;
  678. }
  679.  
  680. static
  681. didWeGet(s,r) char *s, *r; {    /* Looks in string s for response r */
  682.     int lr = strlen(r);        /*  0 means not found, 1 means found it */
  683.     int i;
  684.     debug(F110,"didWeGet",r,0);
  685.     debug(F110," in",s,0);
  686.     for (i = strlen(s)-lr; i >= 0; i--)
  687.     if ( s[i] == r[0] ) if ( !strncmp(s+i,r,lr) ) return( 1 );
  688.     return( 0 );
  689. }
  690.  
  691.  
  692. /* R E S E T -- Reset alarms, etc. on exit. */
  693.  
  694. static
  695. reset ()
  696.     {
  697.     alarm(0);
  698.     signal(SIGALRM,savAlrm);        /* restore alarm handler */
  699. #ifndef OS2
  700.     signal(SIGINT,savInt);        /* restore interrupt handler */
  701. #endif
  702.     }
  703.  
  704. /*  C K D I A L     --  Dial up the remote system */
  705.  
  706. ckdial(telnbr) char *telnbr; {
  707.  
  708.     char c;
  709.     char *i, *j;
  710.     int waitct, status;
  711.     char errmsg[50], *erp;
  712.     MDMINF *pmdminf;    /* pointer to modem-specific info */
  713.     int augmdmtyp;    /* "augmented" modem type, to handle modem modes */
  714.     int mdmEcho = 0;    /* assume modem does not echo */
  715.     int n, n1;
  716.     char *pc;        /* pointer to a character */
  717.  
  718.     if (!mdmtyp) {
  719.         printf("Sorry, you must 'set modem' first\n");
  720.         return(-2);
  721.     }
  722.     if (!local) {
  723.         printf("Sorry, you must 'set line' first\n");
  724.         return(-2);
  725.     }
  726.     if (speed < 0) {
  727.         printf("Sorry, you must 'set speed' first\n");
  728.         return(-2);
  729.     }
  730.         debug(F110,"dial",telnbr,0);
  731.  
  732.     /* Carrier no-wait can be invalidated by ckutio fun and games, jrd */
  733.     if (ttopen(ttname,&local,mdmtyp) < 0) { /* Open, no carrier wait */
  734.         erp = errmsg;
  735.         sprintf(erp,"Sorry, can't open %s",ttname);
  736.         perror(errmsg);
  737.         return(-2);
  738.     }
  739.     pmdminf = ptrtab[mdmtyp-1];    /* set pointer to modem info */
  740.     augmdmtyp = mdmtyp;        /* initialize "augmented" modem type */
  741.  
  742. /* cont'd... */
  743.  
  744.                        /* interdigit waits for tone dial */
  745. /* ...dial, cont'd */
  746.  
  747.  
  748.     waitct = 1*strlen(telnbr) ;    /* compute time to dial worst case */
  749.     waitct += pmdminf->dial_time;    /* dialtone + completion wait times */
  750.     for (i=telnbr; *i; i++)        /* add in pause characters time */
  751.         for (j=pmdminf->pause_chars; *j; j++)
  752.         if (*i == *j) {
  753.             waitct += pmdminf->pause_time;
  754.             break;
  755.             }
  756.  
  757.        printf("Dialing thru %s, speed %d, number %s.\n",ttname,speed,telnbr);
  758.        printf("The timeout for completing the call is %d seconds.\n",waitct);
  759. #ifndef OS2
  760.        printf("Type the interrupt character (^C) to cancel the dialing.\n");
  761. #endif
  762.        debug(F101,ttname,"",speed);
  763.        debug(F101,"timeout","",waitct);
  764.  
  765. /* Hang up the modem (in case it wasn't "on hook") */
  766.  
  767.     if ( tthang() < 0 ) {
  768.         printf("Sorry, Can't hang up tty line\n");
  769.         return(-2);
  770.     }
  771.         if (augmdmtyp == n_ROLM) sleep(1);
  772.  
  773. /* Condition console terminal and communication line */
  774.                 /* place line into "clocal" dialing state */
  775.     if ( ttpkt(speed,DIALING,parity) < 0 )    {
  776.         printf("Sorry, Can't condition communication line\n");
  777.         return(-2);
  778.     }
  779.         if (augmdmtyp == n_ROLM) sleep(1);
  780. /*
  781.  * Establish jump vector, or handle "failure" jumps.
  782.  */
  783.  
  784.     if ( n = setjmp(sjbuf) )        /* if a "failure jump" was taken... */
  785.     {
  786.     alarm ( 0 );            /* disable timeouts */
  787.     if ( n1 = setjmp(sjbuf) )    /* failure while handling failure */
  788.         {
  789.         printf ( "%s failure while handling failure.\n", F_reason[n1] );
  790.         }
  791.     else                /* first (i.e., non-nested) failure */
  792.         {
  793.         signal ( SIGALRM, dialtime );    /* be sure to catch signals */
  794. #ifndef OS2
  795.         if ( signal ( SIGINT, SIG_IGN ) != SIG_IGN )
  796.         signal ( SIGINT, dialint );
  797. #endif
  798.         alarm ( 10 );        /* be sure to exit this section */
  799.         ttclos ();            /* hangup and close the line */
  800.         }
  801.     switch ( n )            /* type of failure */
  802.         {
  803.         case F_time:        /* timed out */
  804.         {
  805.         printf ( "No connection made within the allotted time.\n" );
  806.         debug(F110,"dial","timeout",0);
  807.         break;
  808.         }
  809.         case F_int:            /* dialing interrupted */
  810.         {
  811.         printf ( "Dialing interrupted.\n" );
  812.         debug(F110,"dial","interrupted",0);
  813.         break;
  814.         }
  815.         case F_modem:        /* modem detected a failure */
  816.         {
  817.         printf ( "Failed (\"" );
  818.         for ( pc=lbuf; *pc; pc++ )
  819.             if ( isprint(*pc) )
  820.             putchar(*pc);    /* display printable reason */
  821.         printf ( "\").\n" );
  822.         debug(F110,"dial",lbuf,0);
  823.         break;
  824.         }
  825.         case F_minit:        /* cannot initialize modem */
  826.         {
  827.         printf ( "Cannot initialize modem.\n" );
  828.         debug(F110,"dial","modem init",0);
  829.         break;
  830.         }
  831.         }
  832.     reset();            /* reset alarms, etc. */
  833.     return ( -2 );            /* exit with failure code */
  834.     }
  835.  
  836. /*
  837.  * Set timer and interrupt handlers.
  838.  */
  839.  
  840. /* The following call to ttflui() commented out because ttpkt just did this */
  841. /*  ttflui();    */        /* flush input buffer if any */
  842.  
  843.     savAlrm = signal(SIGALRM,dialtime); /* set alarm handler */
  844. #ifndef OS2
  845.     if ( ( savInt = signal ( SIGINT, SIG_IGN ) ) != SIG_IGN )
  846.     signal ( SIGINT, dialint );    /* set int handler if not ignored */
  847. #endif
  848.     debug(F100,"ckdial giving modem 10 secs to wake up","",0);
  849.     alarm(10);            /* give modem 10 seconds to wake up */
  850.  
  851. /*
  852.  * Put modem in command mode.
  853.  */
  854.  
  855. #define OKAY 1            /* modem attention attempt status */
  856. #define IGNORE 2
  857. #define GOT_O -2
  858. #define GOT_A -3
  859.  
  860. switch (augmdmtyp) {
  861.  
  862. #ifdef ATT7300
  863.     case n_ATTUPC:
  864. /*
  865.   For ATT7300/Unix PC's with their special internal modem. Timeout
  866.   and user interrupts are enabled during dialing.  attdial() is in
  867.   file ckutio.c.  - jrd
  868. */
  869.     {
  870.     alarm(waitct);                /* do alarm properly */
  871.     if (attdial(ttname,speed,telnbr))    /* dial internal modem */
  872.         {
  873.         reset();            /* reset alarms, etc. */
  874.         if ( ! quiet ) printf("Call did not complete.");
  875.         ttclos();            /* close line if open */
  876.         return (-2);            /* return failure */
  877.         }
  878.     reset();                /* reset alarms, etc. */
  879.     ttpkt(speed,CONNECT,parity);        /* cancel dialing ioctl */
  880.     if ( ! quiet ) printf ("Call completed.\07\r\n");
  881.     return(0);     /* no conversation with modem to complete dialing */
  882.     }
  883. #endif /* att7300 */
  884.  
  885.     case n_HAYES:
  886.     case n_HAYESNV:
  887.     while(tries++ < 4) {
  888.         ttol( HAYES.wake_str, strlen(HAYES.wake_str) );    /* wakeup */
  889.         status = 0;
  890.         while ( status <= 0 ) {
  891.         switch (ttinc(0) & 0177) {
  892.             case 'A':            /* echoing, ignore */
  893.             status = GOT_A;
  894.             break;
  895.             case 'T':
  896.             if (status == GOT_A) {
  897.                 mdmEcho = 1;    /* expect echoing later */
  898.                 status = 0;
  899.                 break;
  900.             }
  901.             status = IGNORE;
  902.             break;
  903.             case LF:
  904.             case CR:
  905.             status = 0;
  906.             break;
  907.             case '0':            /* numeric result code */
  908.             augmdmtyp = n_HAYESNV;    /* nonverbal result codes */
  909.             status = OKAY;
  910.             break;
  911.             case 'O':            /* maybe English result code*/
  912.             status = GOT_O;
  913.             break;
  914.             case 'K':
  915.             if (status == GOT_O) {
  916.                 augmdmtyp = n_HAYES;
  917.                 status = OKAY;
  918.                 break;
  919.             }            /* else its default anyway */
  920.             default:
  921.             status = IGNORE;
  922.             break;
  923.             }
  924.         }
  925.         if (status == OKAY) break;
  926.         if (status == IGNORE) ttflui();
  927.         sleep(1);        /* wait before retrying */
  928.     }
  929.     if (status != 0) break;
  930.     longjmp( sjbuf, F_minit );    /* modem-initialization failure */
  931.  
  932. /* cont'd... */
  933.  
  934.                     /* interdigit waits for tone dial */
  935.     case n_MICROCOM:
  936.         {
  937.         jmp_buf savejmp;
  938.         alarm(0);
  939.         xcpy((char *)savejmp, (char *)sjbuf, sizeof savejmp);
  940.         if(setjmp(sjbuf)) {
  941.             /* try the autobaud sequence */
  942.         xcpy((char *)sjbuf, (char *)savejmp, sizeof savejmp);
  943.         alarm(5);
  944.             ttolSlow("44445", MICROCOM.wake_rate);
  945.         waitFor(MICROCOM.wake_str);
  946.         } else {
  947.         alarm(2);
  948.         ttolSlow(MICROCOM.wake_str, MICROCOM.wake_rate);
  949.             waitFor(MICROCOM.wake_str);
  950.         alarm(0);
  951.         xcpy((char *)sjbuf, (char *)savejmp, sizeof savejmp);
  952.         }
  953.     }
  954.     break;
  955.     case n_ATTDTDM:        /* DTDM requires BREAK to wake up */
  956.     ttsndb();        /* Send BREAK */
  957.     break;            /* ttsndb() defined in ckutio.c */
  958.  
  959.     default:            /* place modem into command mode */
  960.     debug(F111,"ckdial default, wake string",pmdminf->wake_str,
  961.           pmdminf->wake_rate);
  962.     ttolSlow(pmdminf->wake_str, pmdminf->wake_rate);
  963.     debug(F110,"ckdial default, waiting for wake_prompt",
  964.           pmdminf->wake_prompt,0);
  965.     waitFor(pmdminf->wake_prompt);
  966.     break;
  967.     }
  968.     debug(F100,"ckdial got wake prompt","",0);
  969.     alarm(0);            /* turn off alarm */
  970.     msleep(500);        /* give things settling time */
  971.     alarm(10);            /* alarm on dialing prompts */
  972.  
  973.  
  974. /* Dial the number */
  975.                 /* put modem into dialing mode */
  976.     ttolSlow(pmdminf->dmode_str, pmdminf->dial_rate);
  977.     if (pmdminf->dmode_prompt) {    /* wait for prompt, if any expected */
  978.     waitFor(pmdminf->dmode_prompt);
  979.     msleep(300);
  980.     }
  981.  
  982.     alarm(0);            /* turn off alarm on dialing prompts */
  983.     alarm(waitct);        /* time to allow for connecting */
  984.     ttflui();            /* clear out stuff from waking modem up */
  985.  
  986.     if (augmdmtyp != n_ATTDTDM)
  987.     sprintf(lbuf,pmdminf->dial_str, telnbr); /* form dialing string */
  988.     else
  989.     sprintf(lbuf,"%s\r",telnbr);
  990.  
  991.     sprintf(lbuf, pmdminf->dial_str, telnbr); /* form dialing string */
  992.     debug(F110,"dialing",lbuf,0);
  993.     ttolSlow(lbuf,pmdminf->dial_rate);    /* send dialing string */
  994.  
  995.     if (augmdmtyp == n_RACAL) { /* acknowledge printout of dialing string */
  996.     sleep(3);
  997.     ttflui();
  998.     ttoc('\r');
  999.     }
  1000.  
  1001. /* cont'd... */
  1002.  
  1003.                     /* interdigit waits for tone dial */
  1004. /* ...dial, cont'd */
  1005.  
  1006.  
  1007. /* Check for connection */
  1008.  
  1009. /*
  1010.  * I believe we also need to look for carrier in order to determine if a
  1011.  * connection has been made.  In fact, for many we may only want to look for
  1012.  * the "failure" responses in order to short-circuit the timeout, and let
  1013.  * carrier be the determination of whether a connection has been made. -- DS
  1014.  */
  1015.  
  1016.     status = 0;
  1017.     strcpy(lbuf,"No Connection");    /* default failure reason */
  1018.     while (status == 0) {
  1019.       switch (augmdmtyp) {
  1020.     default:
  1021.         for (n=0; n < LBUFL-1; n++) { /* accumulate response */
  1022.         lbuf[n] = (ttinc(0) & 0177);
  1023.         if ( lbuf[n] == CR || lbuf[n] == LF ) break;
  1024.         }
  1025.         lbuf[n] = '\0';        /* terminate response from modem */
  1026.         debug(F110,"dial modem response",lbuf,0);
  1027.         if (n) {            /* if one or more characters present */
  1028.         switch (augmdmtyp) {
  1029.           case n_ATTMODEM:
  1030.               if (didWeGet(lbuf,"Answered")) status = CONNECTED;
  1031.               if (didWeGet(lbuf,"Connected")) status = CONNECTED;
  1032.               if (didWeGet(lbuf,"Not connected")) status = FAILED;
  1033.               if (didWeGet(lbuf,"Not Connected")) status = FAILED;
  1034.               if (didWeGet(lbuf,"Busy")) status = FAILED;
  1035.               if (didWeGet(lbuf,"No dial tone")) status = FAILED;
  1036.               if (didWeGet(lbuf,"No Dial Tone")) status = FAILED;
  1037.               if (didWeGet(lbuf,"No answer")) status = FAILED;
  1038.               if (didWeGet(lbuf,"No Answer")) status = FAILED;
  1039.               break;
  1040.           case n_ATTDTDM:
  1041.               if (didWeGet(lbuf,"DENIED")) status = FAILED;
  1042.               if (didWeGet(lbuf,"CHECK OPTIONS")) status = FAILED;
  1043.               if (didWeGet(lbuf,"DISCONNECTED")) status = FAILED;
  1044.               if (didWeGet(lbuf,"ANSWERED")) status = CONNECTED;
  1045.               if (didWeGet(lbuf,"BUSY")) status = FAILED;
  1046.               break;
  1047.           case n_CERMETEK:
  1048.             if (didWeGet(lbuf,"\016A")) {
  1049.             status = CONNECTED;
  1050.             ttolSlow("\016U 1\r",200);    /* make transparent*/
  1051.             }
  1052.             break;
  1053.           case n_DF100:         /* DF100 won't generate some of these */
  1054.           case n_DF200:
  1055.             if (didWeGet(lbuf,"Attached")) status = CONNECTED;
  1056.             /*
  1057.              * The DF100 will respond with "Attached" even if DTR
  1058.              * and/or carrier are not present.    Another reason to
  1059.              * (also) wait for carrier?
  1060.              */
  1061.             if (didWeGet(lbuf,"Busy")) status = FAILED;
  1062.             if (didWeGet(lbuf,"Disconnected")) status = FAILED;
  1063.             if (didWeGet(lbuf,"Error")) status = FAILED;
  1064.             if (didWeGet(lbuf,"No answer")) status = FAILED;
  1065.             if (didWeGet(lbuf,"No dial tone")) status = FAILED;
  1066.             if (didWeGet(lbuf,"Speed:")) status = FAILED;
  1067.             /*
  1068.              * It appears that the "Speed:..." response comes after an
  1069.              * "Attached" response, so this is never seen.  HOWEVER,
  1070.              * it would be very handy to detect this and temporarily
  1071.              * reset the speed, since it's a nuisance otherwise.
  1072.              * If we wait for some more input from the modem, how do
  1073.              * we know if it's from the remote host or the modem?
  1074.              * Carrier reportedly doesn't get set until after the
  1075.              * "Speed:..." response (if any) is sent.  Another reason
  1076.              * to (also) wait for carrier.
  1077.              */
  1078.             break;
  1079.           case n_GDC:
  1080.             if (didWeGet(lbuf,"ON LINE")) status = CONNECTED;
  1081.             if (didWeGet(lbuf,"NO CONNECT")) status = FAILED;
  1082.             break;
  1083.           case n_HAYES:
  1084.           case n_USROBOT:
  1085.             if (didWeGet(lbuf,"CONNECT 1200")) {
  1086.             if (speed != 1200) {
  1087.                 if (ttpkt(1200,DIALING) < 0) {
  1088.                 printf("Can't change speed to 1200\r\n");
  1089.                 } else {
  1090.                 speed = 1200;
  1091.                 status = CONNECTED;
  1092.                 if ( !quiet )
  1093.                   printf("Speed changed to 1200\r\n");
  1094.                 }
  1095.             } /* Expand this to include more speeds */
  1096.             }
  1097.             if (didWeGet(lbuf,"CONNECT")) status = CONNECTED;
  1098.             if (didWeGet(lbuf,"NO CARRIER")) status = FAILED;
  1099.               if (didWeGet(lbuf,"NO DIALTONE")) status = FAILED;
  1100.               if (didWeGet(lbuf,"BUSY")) status = FAILED;
  1101.               if (didWeGet(lbuf,"NO ANSWER")) status = FAILED;
  1102.               if (didWeGet(lbuf,"RING")) status = FAILED;
  1103.               if (didWeGet(lbuf,"ERROR")) status = FAILED;
  1104.             break;
  1105.           case n_PENRIL:
  1106.             if (didWeGet(lbuf,"OK")) status = CONNECTED;
  1107.             if (didWeGet(lbuf,"BUSY")) status = FAILED;
  1108.             if (didWeGet(lbuf,"NO RING")) status = FAILED;
  1109.             break;
  1110.           case n_RACAL:
  1111.             if (didWeGet(lbuf,"ON LINE")) status = CONNECTED;
  1112.             if (didWeGet(lbuf,"FAILED CALL")) status = FAILED;
  1113.             break;
  1114.           case n_ROLM:
  1115.             if (didWeGet(lbuf,"CALLING")) status = 0;
  1116.             if (didWeGet(lbuf,"COMPLETE")) status = CONNECTED;
  1117.             if (didWeGet(lbuf,"FAILED")) status = FAILED;
  1118.             if (didWeGet(lbuf,"NOT AVAILABLE")) status = FAILED;
  1119.             if (didWeGet(lbuf,"LACKS PERMISSION")) status = FAILED;
  1120.             if (didWeGet(lbuf,"NOT A DATALINE")) status = FAILED;
  1121.             /*
  1122.                       Early versions of the Rolm 9751
  1123.               CBX software do not give a CALL COMPLETE indication
  1124.               when dialing an outpool number, but it does seem to
  1125.               return a long string of DELs at that point.
  1126.               (this doesn't really work...)
  1127.             if (didWeGet(lbuf,"\177\177\177")) status = CONNECTED;
  1128.             */
  1129.             break;
  1130.           case n_VENTEL:
  1131.             if (didWeGet(lbuf,"ONLINE!")) status = CONNECTED;
  1132.             if (didWeGet(lbuf,"BUSY")) status = FAILED;
  1133.             if (didWeGet(lbuf,"DEAD PHONE")) status = FAILED;
  1134.             break;
  1135.           case n_CONCORD:
  1136.             if (didWeGet(lbuf,"INITIATING")) status = CONNECTED;
  1137.             if (didWeGet(lbuf,"BUSY")) status = FAILED;
  1138.             if (didWeGet(lbuf,"CALL FAILED")) status = FAILED;
  1139.             break;
  1140.           case n_MICROCOM:
  1141.             /* "RINGBACK" means phone line ringing, continue */
  1142.             if (didWeGet(lbuf,"NO CONNECT")) status = FAILED;
  1143.                     /* trailing speed ignored */
  1144.             if (didWeGet(lbuf,"CONNECT")) status = CONNECTED;
  1145.             if (didWeGet(lbuf,"BUSY")) status = FAILED;
  1146.             if (didWeGet(lbuf,"NO DIALTONE")) status = FAILED;
  1147.             if (didWeGet(lbuf,"COMMAND ERROR")) status = FAILED;
  1148.             if (didWeGet(lbuf,"IN USE")) status = FAILED;
  1149.             break;
  1150.         }
  1151.         }
  1152.         break;
  1153.  
  1154.     case n_DF03:            /* because response lacks CR or NL */
  1155.         c = ttinc(0) & 0177;
  1156.         if ( c == 'A' ) status = CONNECTED;
  1157.         if ( c == 'B' ) status = FAILED;
  1158.         break;
  1159.  
  1160.     case n_HAYESNV:
  1161.         c = ttinc(0) & 0177;
  1162.         if (mdmEcho) {        /* sponge up dialing string */
  1163.         mdmEcho = c!='\r';    /* until return is echoed */
  1164.         break;
  1165.         }
  1166.         if (c == '1') status = CONNECTED;
  1167.         if (c == '3') status = FAILED;
  1168.         if (c == '5') status = CONNECTED;
  1169.         break;
  1170.  
  1171.     case n_UNKNOWN:
  1172.         /** SHOULD WAIT FOR CARRIER OR TIMEOUT -- DS **/
  1173.         break;
  1174.     }                /* switch (augmdmtyp) */
  1175.     }                    /* while status == 0 */
  1176.     alarm(0);                /* turn off alarm on connecting */
  1177.     if ( status != CONNECTED )        /* modem-detected failure */
  1178.     longjmp( sjbuf, F_modem );    /* exit (with reason in lbuf) */
  1179.     msleep(500);            /* allow some time...  */
  1180.     alarm(3);                /* precaution in case of trouble */
  1181.     debug(F110,"dial","succeeded",0);
  1182.     if (augmdmtyp != n_ROLM)        /* Rolm has wierd modem signaling */
  1183.       ttpkt(speed,CONNECT,parity);    /* cancel dialing state ioctl */
  1184.     reset ();                /* reset alarms, etc. */
  1185.     if ( ! quiet )
  1186.     printf ( "Call completed.\07\n" );
  1187.     return ( 0 );            /* return, and presumably connect */
  1188. }
  1189.