Code Confidencebuild 3.0.0.201402161939

Chapter 57. CHAT Scripts

Table of Contents
Chat Script
ABORT Strings
TIMEOUT
Sending EOT
Escape Sequences

The automated conversational scripting supported by the eCos PPP package is a subset of the scripting language provided by the chat command found on most UNIX and Linux systems.

Unlike the chat command, the eCos cyg_ppp_chat() function takes as a parameter a zero-terminated array of pointers to strings. In most programs this will be defined by means of an initializer for a static array, although there is nothing to stop the application constructing it at runtime. A simple script would be defined like this:


static char *chat_script[] =
{
    "ABORT"        ,  "BUSY"        ,
    "ABORT"        ,  "NO CARRIER"  ,
    ""             ,  "ATD5551234"  ,
    "ogin:--ogin:" ,  "ppp"         ,
    "ssword:"      ,  "hithere"     ,
    0
};

The following sections have been abstracted from the public domain documentation for the chat command.

Chat Script

A script consists of one or more "expect-send" pairs of strings, separated by spaces, with an optional "subexpect- subsend" string pair, separated by a dash as in the following example:


    "ogin:--ogin:"     ,  "ppp"       ,
    "ssword:"          ,   "hello2u2" ,
    0

This script fragment indicates that the cyg_ppp_chat() function should expect the string "ogin:". If it fails to receive a login prompt within the time interval allotted, it is to send a carriage return to the remote and then expect the string "ogin:" again. If the first "ogin:" is received then the carriage return is not generated.

Once it received the login prompt the cyg_ppp_chat() function will send the string "ppp" and then expect the prompt "ssword:". When it receives the prompt for the password, it will send the password "hello2u2".

A carriage return is normally sent following the reply string. It is not expected in the "expect" string unless it is specifically requested by using the "\r" character sequence.

The expect sequence should contain only what is needed to identify the string. It should not contain variable information. It is generally not acceptable to look for time strings, network identification strings, or other variable pieces of data as an expect string.

To help correct for characters which may be corrupted during the initial sequence, look for the string "ogin:" rather than "login:". It is possible that the leading "l" character may be received in error and you may never find the string even though it was sent by the system. For this reason, scripts look for "ogin:" rather than "login:" and "ssword:" rather than "password:".

A very simple script might look like this:


    "ogin:"    , "ppp"       ,
    "ssword:"  , " hello2u2" ,
    0

In other words, expect "....ogin:", send "ppp", expect "...ssword:", send "hello2u2".

In actual practice, simple scripts are rare. At the very least, you should include sub-expect sequences should the original string not be received. For example, consider the following script:


    "ogin:--ogin:"  , "ppp"     ,
    "ssword:"       , "hello2u2",
    0

This would be a better script than the simple one used earlier. This would look for the same "login:" prompt, however, if one was not received, a single return sequence is sent and then it will look for "login:" again. Should line noise obscure the first login prompt then sending the empty line will usually generate a login prompt again.