home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / PPPD11.ZIP / CHAT.MAN < prev    next >
Text File  |  1997-09-14  |  25KB  |  560 lines

  1. PPPD for DOS 0.6 beta
  2.  
  3. NAME
  4.        chat - Automated conversational script with a modem
  5.  
  6. SYNOPSIS
  7.        chat [ options ] script
  8.  
  9. DESCRIPTION
  10.        The chat program defines a conversational exchange between
  11.        the computer and the modem.  Its  primary  purpose  is  to
  12.        establish the connection between the Point-to-Point Proto-
  13.        col packet driver (pppd.exe) and the remote's PPP process.
  14.  
  15. DOS NOTES
  16.        The DOS version incorporates two flavours of the  program, 
  17.        one intended for use with the  'connect' option  from pppd 
  18.        (chat.exe) and another for standalone use (chat0.exe). The 
  19.        chat.exe  program  requires  that  pppd.exe be  present in 
  20.        memory,  as  its access  to COM  ports is  done through  a 
  21.        private interface  via the  packet driver  interrupt.  The 
  22.        chat0.exe program directly accesses  COM ports  and leaves 
  23.        the DTR line high after exiting, in much the same way that 
  24.        kermit and other  DOS terminal  programs do  when quitting 
  25.        without resetting the COM port.
  26.  
  27.        This means that chat0.exe accepts options for selecting  a 
  28.        port, while chat.exe gets whatever port pppd.exe is using. 
  29.        If you don't specify a COM  port with  chat0.exe, COM1  is 
  30.        used by default.  The OPTIONS sections  will note  options 
  31.        that are applicable to both executables and those that are 
  32.        applicable to chat0.exe only.
  33.  
  34.        The command line parsing done by DOS C compilers is  quite 
  35.        different from *NIX regarding quotes.  It  means that  you 
  36.        must use "" for quoting strings  with embedded  blanks and 
  37.        '' for inserting empty  strings. It  seems that  the empty 
  38.        string "" doesn't store a null  argument under  DOS, which 
  39.        will cause the CHAT script not to work as intended.
  40.  
  41.        Some examples are in oder:
  42.  
  43.            "CONNECT 14400"       generates the single string
  44.                                  CONNECT 14400.
  45.  
  46.            ""                    no string is generated, the C
  47.                                  startup code simply skips these.
  48.  
  49.            ''                    generates one single string
  50.                                  which is empty.
  51.  
  52.            \"\"                  generates one single string
  53.                                  which is empty.
  54.  
  55.            'CONNECT 14400'       tries to generate two strings,
  56.                                  CONNECT and 14400', causing an
  57.                                  unterminated quote error.
  58.  
  59.            '\"CONNECT 14400\"'   tries to generate two strings,
  60.                                  "CONNECT and 14400", causing an
  61.                                  unterminated quote error.
  62.  
  63.            "'CONNECT 14400'"     generates the single string
  64.                                  CONNECT 14400.
  65.  
  66.            "\'CONNECT 14400\'"   generates the single string
  67.                                  'CONNECT 14400'.
  68.  
  69.            "'\"CONNECT 14400\"'" generates the single string
  70.                                  "CONNECT 14400".
  71.  
  72.        This change  in behavior  doesn't apply  when reading  the 
  73.        CHAT script from a file, because  the program  code is  in 
  74.        charge of interpreting the characters and neither DOS  nor 
  75.        the C compiler interferes with it.
  76.  
  77. OPTIONS
  78.        -p <COMn>                                 (CHAT0.EXE only)
  79.               Specifies  the  COM port  to use  for communicating 
  80.               with the  modem.  Ports  COM1 through  COM4 can  be 
  81.               used; the  standard  base  address   and  IRQ   are 
  82.               asssumed unless you change  the default  with other 
  83.               options.  Basic testing (through  BIOS) is  done to 
  84.               ensure  COM  availability.  If  chat0  fails   with
  85.               message:
  86.  
  87.                   Invalid COM device COM?
  88.  
  89.               Then probably you  have  a  non  standard  COM port
  90.               setup.  Omit the -p option  from configuration  and
  91.               specify  COM  port  values with  the  following two
  92.               options, -b and -i.
  93.  
  94.        -b <port base>                            (CHAT0.EXE only)
  95.               Specifies the base address for the COM port, in the 
  96.               event that it is  a non-standard  one.  The  number 
  97.               can be entered in hex, octal or decimal,  following 
  98.               the C language rules for parsing numbers (0xnnn  is 
  99.               hex for  example).  No  attempt is  made to  verify 
  100.               that a valid COM port exists at the address, so use 
  101.               this option with care.
  102.  
  103.        -i <IRQ number>                           (CHAT0.EXE only)
  104.               Specifies the IRQ number used by the COM  port. The 
  105.               same considerations as above apply.
  106.  
  107.        -s <baud rate>                            (CHAT0.EXE only)
  108.               Specifies   the   speed  for   modem  to   computer 
  109.               communication.    Up   to   115200   baud  can   be 
  110.               programmed, but beware that serial ports  that have 
  111.               the old 8250 UART cannot handle speeds higher  than 
  112.               9600 reliably.  The number can be  entered in  hex, 
  113.               octal or decimal, as in the above options.
  114.  
  115.        -f <chat file>
  116.               Read the chat script from the chat file. The use of 
  117.               this  option  is mutually  exclusive with  the chat 
  118.               script parameters.  Multiple lines are permitted in 
  119.               the  file.   Space  or  horizontal  tab  characters 
  120.               should be used to separate the strings.
  121.  
  122.        -t <timeout>
  123.               Set  the  timeout  for  the expected  string to  be 
  124.               received. If the string is not received within  the 
  125.               time limit, then the reply string is not  sent.  An 
  126.               alternate reply  may be  sent, or  the script  will 
  127.               fail  if  there is  no alternate  reply string.   A 
  128.               failed  script  will  cause  the  chat  program  to 
  129.               terminate with a nonzero error code.
  130.  
  131.        -r <report file>
  132.               Set the file for output of  the report  strings. If 
  133.               you use the keyword  REPORT, the  resulting strings 
  134.               are written  to this  file. If  this option  is not 
  135.               used and you still use REPORT keywords, the  stderr 
  136.               file is used for the report strings.
  137.  
  138.        -e     Start  with  the echo option turned on. Echoing may 
  139.               also be turned on or off at specific points in  the 
  140.               chat script by using the ECHO keyword. When echoing 
  141.               is enabled, all output from the modem is  echoed to 
  142.               DOS standard error device.
  143.  
  144.        -v     Request that the chat script be executed in verbose 
  145.               mode.  The chat program will log all text  received 
  146.               from the modem, and the output strings sent, to DOS 
  147.               standard output, which can be redirected.
  148.  
  149.        -V     Request that the chat script be executed in  stderr 
  150.               verbose mode. The chat  program will  then log  all 
  151.               text  received  from  the  modem,  and  the  output 
  152.               strings sent,  to  the DOS  standard error  device. 
  153.               This device  is usually  the local  console at  the 
  154.               station running the chat or pppd program.
  155.  
  156.        script If the script is not specified as a  file with  the 
  157.               -f option then the  remaining parameters  are taken 
  158.               as the script.
  159.  
  160. CHAT SCRIPT
  161.        The chat script defines the communications.
  162.  
  163.        A script consists of  one or  more "expect-send"  pairs of 
  164.         strings,   separated   by   spaces,   with  an   optional 
  165.        "subexpect-subsend" string pair, separated by a dash as in 
  166.        the following example:
  167.  
  168.               ogin:-BREAK-ogin: ppp ssword: hello2u2
  169.  
  170.        This line indicates that  the chat  program should  expect 
  171.        the string "ogin:". If it fails to receive a login  prompt 
  172.        within the time interval allotted, it is to  send a  break 
  173.        sequence to the remote and then expect the string "ogin:". 
  174.        If the first "ogin:" is received  then the  break sequence 
  175.        is not generated.
  176.  
  177.        Once it receives the login prompt,  the chat  program will 
  178.        send the string ppp and then expect the  prompt "ssword:". 
  179.        When it receives the prompt for the password, it will send 
  180.        the password hello2u2.
  181.  
  182.        Chat scripts always begin at the 'expect' condition,  so a
  183.        nul  '' expectation should be used as the first string  if
  184.        no  response  is  to be received from the modem  when  the
  185.        script begins execution. This is the most common case.
  186.  
  187.        Some  "expect-send"  strings are interpreted in a  special
  188.        way  by chat, like report strings, abort conditions and  a
  189.        few others, more on this later.
  190.  
  191.        A carriage  return is  normally sent  following the  reply 
  192.        string. It is not expected in  the "expect"  string unless 
  193.        it is  specifically indicated  by using  the \r  character 
  194.        sequence.
  195.  
  196.        The expect sequence should contain only what is  needed to 
  197.        identify the string. Since it is normally stored in a disk 
  198.        file, it should not contain variable  information.  It  is 
  199.        generally not acceptable to look for time strings, network 
  200.        identification strings, or other  variable pieces  of data 
  201.        as an expect string.
  202.  
  203.        To  help  correct for  characters which  may be  corrupted 
  204.        during the initial sequence, look for  the string  "ogin:" 
  205.        rather than "login:". It is possible that the  leading "l" 
  206.        character may be received in error, and you may never find 
  207.        the string, even though it was  sent by  the system.   For 
  208.        that reason, scripts look for "ogin:" rather than "login:" 
  209.        and "ssword:" rather than "password:".
  210.  
  211.        A very simple script might look like this:
  212.  
  213.               ogin: ppp ssword: hello2u2
  214.  
  215.        In  other  words,  expect  ....ogin:,  send   ppp,  expect 
  216.        ...ssword:, send hello2u2.
  217.  
  218.        In actual practice, simple scripts are  rare. At  the vary 
  219.        least, you should include sub-expect sequences in case the 
  220.        original string is not received. For example, consider the 
  221.        following script:
  222.  
  223.               ogin:--ogin: ppp ssowrd: hello2u2
  224.  
  225.        This would be a  better script  than the  simple one  used 
  226.        earlier.  This would look for the same "login:" prompt; if 
  227.        one were not received, a single  return sequence  would be 
  228.        sent, and then chat would look for "login:" again.  Should 
  229.        line noise  obscure the  first login  prompt, sending  the 
  230.        empty line will usually generate another login prompt.
  231.  
  232. ABORT STRINGS
  233.        Many  modems  will  report  the status  of the  call as  a 
  234.        string.  These strings may be CONNECTED  or NO  CARRIER or 
  235.        BUSY.   It  is  often  desirable to  terminate the  script 
  236.        should  the  modem  fail  to  connect  to the  remote. The 
  237.        difficulty is that a script  will not  know exactly  which 
  238.        modem  string  it  may  receive.  On  one attempt,  it may 
  239.        receive  BUSY  while  the  next  time  it  may  receive NO 
  240.        CARRIER.
  241.  
  242.        These "abort" strings may be specified in the script using 
  243.        the ABORT sequence, as in the following example:
  244.  
  245.               ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212
  246.               CONNECT
  247.  
  248.        This sequence will expect nothing and send the string ATZ. 
  249.        The expected response to this is the string OK.  When chat 
  250.        receives OK, the string  ATDT5551212 dials  the telephone.  
  251.        The expected string is CONNECT.  If the string  CONNECT is 
  252.        received,  the  remainder  of  the  script   is  executed. 
  253.        However, should the modem find a  busy telephone,  it will 
  254.        send  the  string  BUSY,  matching  the   abort  character 
  255.        sequence.  The script will  then fail  because it  found a 
  256.        match to the abort string.  If it  receives the  string NO 
  257.        CARRIER, it will abort for the same reason.  Either string 
  258.        may be received.  Either  string will  terminate the  chat 
  259.        script.
  260.  
  261.  
  262. REPORT STRINGS
  263.        A  "report"  string is  similar to  an abort  string.  The 
  264.        difference is that the strings, and  all characters  up to 
  265.        the next control character  (such as  a carriage  return), 
  266.        are written to the report file.
  267.  
  268.        The report strings may be used to isolate the transmission 
  269.        rate of the modem's connect string and return the value to 
  270.        the chat user.  The  analysis of  the report  string logic 
  271.        occurs  in  conjunction with  the other  string processing 
  272.        such as looking for the expect string. The use of the same 
  273.        string for  a report  and abort  sequence is  probably not 
  274.        very useful, however, it is possible.
  275.  
  276.        The report strings do not change  the return  code of  the 
  277.        program.
  278.  
  279.        These report strings may be specified in the  script using 
  280.        the REPORT sequence, as in the following example:
  281.  
  282.               REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT ''
  283.               ogin: account
  284.  
  285.        This  sequence  will expect  nothing and  send the  string 
  286.        ATDT5551212 to dial the telephone.  The expected string is 
  287.        CONNECT. If the string CONNECT is  received the  remainder 
  288.        of the script is  executed. In  addition the  program will 
  289.        write to  the expect  file the  string "CONNECT"  plus any 
  290.        characters which follow it, such as the connection rate.
  291.  
  292. ECHO
  293.        The  ECHO  keyword controls  whether the  output from  the 
  294.        modem is echoed to stderr.  This behavior may be specified 
  295.        with the -e option, but it  can also  be controlled  using 
  296.        the ECHO keyword.  The "expect-send" pair ECHO ON  enables 
  297.        echoing, and ECHO OFF disables it.  With this  keyword you 
  298.        can  select  which  parts  of the  conversation should  be 
  299.        visible.  For instance, with the following script:
  300.  
  301.               ABORT   'BUSY'
  302.               ABORT   'NO CARIER'
  303.               ''      AT&F
  304.               OK\r\n  ATD1234567
  305.               \r\n    \c
  306.               ECHO    ON
  307.               CONNECT \c
  308.               ogin:   account
  309.  
  310.        ...   all  output resulting  from modem  configuration and 
  311.        dialing is not visible, but starting with the  CONNECT (or 
  312.        BUSY) message, everything will be echoed.
  313.  
  314. TIMEOUT
  315.        The  initial  timeout  value  is  45  seconds. This may be 
  316.        changed using the -t parameter.
  317.  
  318.        To change the timeout value for the  next  expect  string, 
  319.        the following example may be used:
  320.  
  321.               ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin:
  322.               TIMEOUT 5 assword: hello2u2
  323.  
  324.        This will change the timeout to 10 seconds when it expects 
  325.        the  login:  prompt.  The  timeout  is  then changed  to 5 
  326.        seconds when it looks for the password prompt.
  327.  
  328.        The timeout, once changed, remains in effect until  it  is 
  329.        changed again.
  330.  
  331. INTERACTIVE MODE
  332.        A  very  basic terminal mode can be entered by  using  the
  333.        TERMINAL ON keyword combination. It only understands ASCII
  334.        keystrokes  and  BACKSPACE, so don't expect a  full  blown
  335.        ANSI terminal emulator. It might be useful for  completing
  336.        login sequences, consider the following example:
  337.  
  338.               ABORT    'BUSY'
  339.               ABORT    'NO CARIER'
  340.               ''       AT&F
  341.               OK\r\n   ATD1234567
  342.               CONNECT  \c
  343.               TERMINAL ON
  344.               ''
  345.  
  346.        After receiving the CONNECT string, chat goes into terminal
  347.        mode and you can manually log into the remote system.  When
  348.        you are done, press ESC and the chat script resumes. As the
  349.        next expect-send pair expects nothing, the chat script ends
  350.        with a success exit code.
  351.  
  352.        Note how TERMINAL ON is introduced at a point of the script
  353.        where  you should normally place an expect string, this  is
  354.        a  requeriment for a proper interpretation of the  command.
  355.        The  example  shown satisfies this requeriment by using  \c
  356.        as  the send string in the line above TERMINAL ON, it means
  357.        that nothing  is sent after receiveing the  CONNECT string,
  358.        but the send part of the expect-send pair is completed  and
  359.        chat looks for an expectation as the next string.
  360.  
  361. GRABBING VALUES SENT BY REMOTE
  362.        Some  login procedures send back useful  information  about
  363.        the connection  when you stablish a connection. This is the
  364.        case  for SLIP logins, where the local and remote  IPs  are
  365.        sent  by the remote after succesful login.  You  definately
  366.        want to get this information, in order to  proper configure
  367.        your  Internet software. For helping in such situations,  a
  368.        few directives was  added to chat scripting language.  What
  369.        these directives do is create a DOS batch file which can be
  370.        run after  chat script completion for  setting  environment
  371.        variables with the values received  through the wire. These
  372.        directives are:
  373.  
  374.               GRABIP varname
  375.               GRABNUM varname
  376.               GRABSTR varname
  377.  
  378.        The varname argument specifies  the name of the environment
  379.        variable that will receive the collected value. Each GRABxx
  380.        directive is specialized in parsing determined text formats
  381.        like IP numbers, decimal numbers and generic strings.  They
  382.        always  parse words, so leading whitespace is discarded and
  383.        the scan  stops at the first trailing withespace.  Lets see
  384.        and example:
  385.  
  386.               ABORT    'BUSY'
  387.               ABORT    'NO CARIER'
  388.               ''       AT&F
  389.               OK\r\n   ATD1234567
  390.               CONNECT  ''
  391.               ogin:    myuserid
  392.               assword: hello2u2
  393.               GRABIP   MYIP
  394.               ''       ''
  395.               GRABIP   REMIP
  396.               'now.'
  397.  
  398.        After  the CONNECT expectation, the nul string sends a  CR
  399.        to the remote. A normal *NIX login sequence follows,  then
  400.        the GRABIP directive  is used for  retrieving the local IP
  401.        which the remote sends after login. The line below expects
  402.        nothing and sends a CR, and GRABIP directive is used again
  403.        for retrieving the remote IP. The script ends by expecting
  404.        "now." which is the tail for the string "SLIP begins now."
  405.        sent by the remote after starting his end SLIP process.
  406.  
  407.        The  same  rules for TERMINAL ON applies here,  the GRABxx
  408.        directives  should  start at an expectation point  in  the
  409.        chat  script, and they must be continued by an expectation
  410.        string too.
  411.  
  412.        When  the chat script ends, you should have a  CHATENV.BAT
  413.        file which looks like:
  414.  
  415.             set MYIP=192.168.1.1
  416.             set REMIP=192.168.1.2
  417.  
  418.        By executing this  batch file, you  get the desired values
  419.        into the MYIP and REMIP environment variables.
  420.  
  421. SENDING EOT
  422.        The special reply string  of EOT  indicates that  the chat 
  423.        program should send an EOT character to the  remote.  This 
  424.        is normally the End-of-file character sequence.   A return 
  425.        character is not sent following the EOT.  The EOT sequence 
  426.        may be embedded into  the send  string using  the sequence 
  427.        ^D.
  428.  
  429. GENERATING BREAK
  430.        The  special  reply  string  of BREAK  will cause  a break 
  431.        condition to be sent. The break is a special signal on the 
  432.        transmitter. The normal processing on the  receiver is  to 
  433.        change the  transmission rate.   It may  be used  to cycle 
  434.        through  the  available transmission  rates on  the remote 
  435.        until you are able to receive a valid  login prompt.   The 
  436.        break sequence may be embedded  in the  send string  using 
  437.        the \K sequence.
  438.  
  439. ESCAPE SEQUENCES
  440.        The expect and reply strings may contain escape sequences. 
  441.        All of the sequences are legal in the reply string.   Many 
  442.        are legal in the expect.  Those which are not valid in the 
  443.        expect sequence are so indicated.
  444.  
  445.        ''     Expects or sends a null string. If you send a  null 
  446.               string, it  will still  send the  return character. 
  447.               This sequence may be either a  pair of  apostrophes 
  448.               or a pair of quote characters.
  449.  
  450.        \b     represents a backspace character.
  451.  
  452.        \c
  453.               Suppresses  the  newline at  the end  of the  reply 
  454.               string. This is the only method of sending a string 
  455.               without a trailing return character. It must be  at 
  456.               the  end  of  the  send string.   For example,  the 
  457.               sequence "hello\c" will simply send the  characters 
  458.               h, e, l, l, o.  (Not valid in expect.)
  459.  
  460.        \d     Delay for  one second.   The program  uses sleep(1) 
  461.               which will delay to a maximum of one  second.  (Not 
  462.               valid in expect.)
  463.  
  464.        \K     Insert a BREAK (not valid in expect).
  465.  
  466.        \n     Send a newline or linefeed character.
  467.  
  468.        \N     Send a  null character.  The same  sequence may  be 
  469.               represented by \0.  (Not valid in expect.)
  470.  
  471.        \p
  472.               Pause  for  a fraction  of a  second. The  delay is 
  473.               1/10th of a second.  (Not valid in expect.)
  474.  
  475.        \q     Suppress writing the string to the SYSLOG file. The 
  476.               string ??????  is written to the log in  its place. 
  477.               (Not valid in expect.)
  478.  
  479.        \r     Send or expect a carriage return.
  480.  
  481.        \s     Represents a space character  in the  string.  This 
  482.               may be used when it is not desirable  to quote  the 
  483.               strings which  contains spaces.   The sequence  'HI 
  484.               TIM' and HI\sTIM are the same.
  485.  
  486.        \t     Send or expect a tab character.
  487.  
  488.        \\     Send or expect a backslash character.
  489.  
  490.        \ddd   Collapse the octal digits (ddd) into a single ASCII 
  491.               character   and   send   that   character.    (Some 
  492.               characters are not valid in expect.)
  493.  
  494.        ^C     Substitute the sequence with the control  character 
  495.               represented by C, where C is a printable character.  
  496.               For example, the character DC1 (17) is shown as ^Q.  
  497.               (Some characters are not valid in expect.)
  498.  
  499. TERMINATION CODES
  500.        The  chat  program  will  terminate  with   the  following 
  501.        completion (return) codes.
  502.  
  503.        0      Normal termination of the  program. This  indicates 
  504.               that the  script was  executed without  error to  a 
  505.               normal conclusion.
  506.  
  507.        1      One or more of  the parameters  are invalid,  or an 
  508.               expect  string  was  too  large  for  the  internal 
  509.               buffers.  This indicates that  the program  was not 
  510.               properly executed.
  511.  
  512.        2      An  error  occurred  during  the  execution  of the 
  513.               program.   This  may  be  due  to  a read  or write 
  514.               operation failing for some reason or chat receiving 
  515.               a signal such as SIGINT.
  516.  
  517.        3      A timeout event occurred when there  was an  expect 
  518.               string without having a "-subsend" string. This may 
  519.               mean that you did not program the script  correctly 
  520.               for the condition,  or that  some unexpected  event 
  521.               has occurred and the expected string  could not  be 
  522.               found.
  523.  
  524.        4      The first  string  marked  as  an  ABORT  condition 
  525.               occurred.
  526.  
  527.        5      The  second  string  marked  as  an ABORT condition 
  528.               occurred.
  529.  
  530.        6      The third  string  marked  as  an  ABORT  condition 
  531.               occurred.
  532.  
  533.        7      The  fourth  string  marked  as  an ABORT condition 
  534.               occurred.
  535.  
  536.        ...    The other termination codes  also indicate  strings 
  537.               marked as an ABORT condition.
  538.  
  539.        Using the termination code,  it is  possible to  determine 
  540.        which  event  terminated the  script.  It  is possible  to 
  541.        decide if the string "BUSY" was received from the modem as 
  542.        opposed to "NO DIAL TONE". While  the first  event may  be 
  543.        retried, the second will  probably have  little chance  of 
  544.        succeeding during a retry.
  545.  
  546. AUTHORS
  547.        DOS port by Antonio Lopez Molero, <tonilop@redestb.es>.
  548.  
  549. NOTES
  550.        You  can use CTRL+BREAK to abort the program  before  CHAT
  551.        script  interpretation  is  done. An  exit  code  of  2 is
  552.        returned in that case.  Note that CTRL+C may not work, use
  553.        CTRL+BREAK.
  554.  
  555. COPYRIGHT
  556.        The chat program is in the public domain. This is  not the 
  557.        GNU public license. If it breaks then you get to keep both 
  558.        pieces.
  559.  
  560.