 Dialup 2.57 - deal with the modem and a sana slip or ppp device.
 ###############################################################


 The program is residentable (pure with the help of cres.o)

 HINT: To test the program, use the option TEST. This performs a modem internal
 ====  loopback instead of a real CONNECT. You can see what will go on
       during CONNECT, HANGUP, etc..
       You can even ping yourself or ftp, etc.. (at least with AS225)

 It is possible to set any option in ENV:Dialup (Setenv Dialup PASSWORD=ItsMe)
 ONLY the FIRST LINE gets parsed!!!!!!!!!!!!!!!!
 Before you start using it (with the settings done to ENV:Dialup) you should
 check everything with 'dialup DEfaults ALL'


 Description of parameters:
 ++++++++++++++++++++++++++

 The template is:

 Dialup [COMMAND] [OPTIONS]

 WARNING:
 ========

 Please  note, that COMMAND is optional, too. This means, that if you accept
 the default command (TOGGLE) any misspelled option gets the COMMAND instead
 of  the  default  one and probably pops up the usage requester. Every other
 wrong  option  (or  even  the  first,  when you specified a COMMAND, gets a
 PHONENUMBER.  This  is  not  my  fault, this is the documented behaviour of
 dos.library/ReadArgs() on /M paramters.


 COMMAND=CMD
 ===========

 The default is TOGGLE.
 The command can be specified without keyword.
 The first word of the commandline, which is not a keyword or switch of the
 template, is taken as the command.
 Possible commands:

 CONNECT=CO              Try to build a modem connection.
                         Basically this performs:

                             ATZ1 ATDS1 sana online

                         If you want to be sure, that the connection is
                         established or buildt, when you start ftp or
                         somthing, write a script which calls

                             Dialup CONNECT QUIET

                         before the net application. QUIET suppress' the
                         warning, if you are already connected.
                         Result: 1 if success, 5 if modem is already online

 HANGUP=HA               Break a connection. This even works during full
                         data transfer. (Cause it sucks :-) the serial line)
                         Basically this performs:

                             +++ ATZ1 sana offline

                         If you have a feed, which calls you when packets
                         arrive, you will be called back. To make the modem
                         take the call, the NORECONNECT option must not be
                         set.
                         Result: 0 if success

 TOGGLE=TO               Toggles between CONNECT and HANGUP, depending on
                         carrier
                         Result: see CONNECT/HANGUP

 TAKE=TA                 Sends a ATA\r (MODEMOFFHOOKCMD=MOH) to the modem
                         after RINGS=RGS\KN rings are detected
                         (MODEMRING=MRG\K) and makes sana device online
                         If a carrier is detected on startup only the sana
                         device is made online.
                         Result: 3 if success

 QUERY=QU                Querys the modem for some information, even when
                         connected. This will work only with the NODTRIGNORE
                         switch not set (or you configured the modem to
                         ignore DTR anyway).
                         Basically this performs:

                             sana offline  +++  ATI2  ATO  sana online

                         See MODEMQUERYCMD for the type of information
                         gathered from modem.
                         Result: 2 if success

 OFFLINE=OF              sana offline
                         Result: 0 if success

 ONLINE=ON               sana online
                         Result: 0 if success

 CARRIERDETECT=CD        sana offline, if no carrier and online if carrier.
                         Meaningfull options: AUTOANSWER=AA and if this is 
                         set RINGS=RGS and MODEMSETTINGSCONNECT=MSC
                         Result: 0 if offline, 5 if online

 CHECK=CH                Possible at any time! It only sets a returncode:
                         Result: 0 if no carrier, 5 if carrier
                   Note:
                         For checking the serial line without hitting
                         the hardware directly, it is neccessary to
                         offline/online the slip device to open the
                         serial.device. This normaly doesn't disturb an
                         ongoing transmission.

 DEFAULT=DE              Query any option for its default. Helpfull to see
                         what will be sent to modem, and chated with your
                         remote site. Use GIVEALLSETTINGS=ALL if you want
                         to see all the default parameters (including
                         ENV:DIALUP) or name any specific.

                             1> setenv DIALUP "MSC=ATsomething"
                             1> Dialup DEFAULT MODEMSETTINGSCONNECT
                             MODEMSETTINGSCONNECT=MSC/K: ATsomething

                         or 

                             1> Dialup DEFAULT GIVEALLSETTTINGS
                             CONNECTSTRING=CS/F: 19200/V42b
                             SANAUNIT=SAU/K/N: 0
                             SANADEVICE=SAD/K: Networks/rhcslip.device
                             NORECONNECT=NRC/S: OFF

                             [ .. ]

                             RINGS=RGS/K/N: 1
                             MODEMCONNECTTIME=MCT/K/N: 40
                             REDIALDELAY=RDD/K/N: 60
                             PHONENUMBER=PN/K/M: ATDS1 
                             MODEMSETTINGSCONNECT=MSC/K: ATZ1


 OPTIONS
 =======

 Note:
  - All options can be kept set for any of the above commands, but not all
    have a meaning to a specific command.

  - For any specified string which gets compared to an answer from the modem
    it is possible to use these patterns:

        Pattern Matches
        ------- -------
           ?    any single character
           c*   zero or more occurrences of character c
           c+   one or more occurrences of character c
           \?   a question mark (?)
           \*   an asterisk (*)
           \+   a plus sign (+)
      
        Any other character must match exactly.
        The following table lists some examples:

        Pattern Matches
        ------- -------
          abc   only abc
          ab*c  ac, abc, or abbc
          ab+c  abc, abbc, or abbbc
          ab?*c a string starting with ab and ending in c, for
                example, abxyzc
          ab\*c only ab*c

  - Multiple strings:

        If there is more than one possible string to come from the modem
        (which is neccesary to continue the conversation, not at CS!)
####### you can specify all of them, sparated by '|'.
#NOTE:# To specify '|' use '?'.
#######
        Example:  MOK="OK|DONE"


 MODEMSETTINGSCONNECT=MSC/K  Command string to send to the modem before 
                         every attempt to connect. If you don't want to
                         send anything use MSC ""
                         Default: ATZ1

 PHONENUMBER=PN/K/M      The phonenumber(s) to dial.
                         If the parameter has a leading 'AT' or '!' no ATD
                         is sent before the number. ('!' will be stripped)
                         Default: S1                    -> ATDS1

                         Example: 1234                  -> ATD1234
                                  ATDP1234              -> ATDP1234
                                  !foobar               -> foobar

                                  pn S1 pn=S1 pn ATDP1234\
                                           -> ATDS1 ATDS1 ATDP1234
                                 If the call fails with BUSY, it would wait
                                 the REDIALDELAY and try again. If this
                                 fails, too, it immediately trys 1234.

                Warning: Everything what cannot be identifyed as an option
                =======  or a COMMAND will get a phonenumber. This is not
                         my fault, this is the documented behaviour
                         of dos.library/ReadArgs() on /M paramters.


 REDIALDELAY=RDD/K/N     Seconds to wait after a BUSY before calling the
                         *same* number again. If you specify 0 it will NOT
                         retry on BUSY.
                         Default: 180

 CONNECTSTRING=CS/K      This string is searched for in the connectstring
                         received from modem. If its not found a requester
                         pops up and tells you the actual connect.
                         If you specify CONNECT you will never see a
                         requester. With this parameter it is possible to
                         use patterns. (see above)
                         Default: "CONNECT*?19200/V42b"


 MODEMCONNECTTIME=MCT/K/N  The time in seconds, the modem needs to dial and
                         handshake with the remote site.
                         Default: 61

 SANADEVICE=SAD/K,       sana device to use
                         Default: "NetWorks/rhcslip.device"

 SANAUNIT=SAU/K/N,       sana unit to use
                         Default: 0

 SANACONFIGFILE=SCF/K,   config file of the sana device
                         Examples:
                              ppp%d.config, ppp0.config, sys:devs/myconfig

                         Default: "ENV:SANA2/slip0.config"

 REPORTFILE=RPF/K        Where to put the report of the serial communication.
                         Default: stdout
                         Note: I've never observed that dialup looses *ANY*
                         character. If you have troubles with the serial
                         communication, it is sometimes helpfull to send
                         the output to a file and view it with:
                             1> type <reportile> hex

 RINGS=RGS/K/N           Number of rings to wait before the modem should
                         take an icomming call. This takes effect only
                         after a HANGUP or CARRIERDETECT with AUTOANSWER!
                         With the TAKE command this in the number of RINGs
                         to receive from the modem, before takeing the
                         call. For TAKE it is possible to specify 0.
                         Default: 1

 LOGINPROMPT=LIP/K       Prompt of the remote site to enter your name.
                         To skip login and password communication use
                         LIP="".
                         Default: "ogin:"

 LOGINNAME=LIN/K         Name to send after receiving the LOGINPROMPT. If
                         not specified it will be taken from the environment
                         variable HOSTNAME.
                         No default.

 LOGINTIMEOUT/K/N        Seconds to wait for the loginprompt of the remote
                         site.
                         Default: 3

 PASSWORDPROMPT=PWP/K    Prompt of the remotesite to enter your password.
                         With this parameter it is possible to use patterns,
                         too. See LOGINPROMPT=LIP
                         To skip password communication use PWP="".
                         Default: "assword:"

 PASSWORD=PW/K           String to send after the PASSWORDPROMPT is received.
                         No default.

 SNDLOGINNAME=SLIN/K     This gets sent, if specified at all, after receiving
                         what is set for                     (no default)

 SNDLOGINPROMPT=SLIP/K   Default: ogin:


 SNDPASSWORD=SPW/K       This gets sent, if specified at all, after receiving
                         what is set for:                     (no default)

 SNDPASSWORDPROMPT=SPWP/K Default: "assword:"

 LOGINOK=LOK/K,          Message of the remote site after succesfull login.
                         Use LOK "" to skip this check.
                         Default: "Packet mode enabled"
 
 LOGINOKTIMEOUT=LOT/K/N  The timeout (in seconds) for the answer (LOK) to a
                         successfull login.
                         Default: 3


 NODTRIGNORE=NDI/S       Disable the sending of AT&D0 to the modem before a
                         CONNECT and AT&D2 after HANGUP.

 MODEMQUERYCMD=MQC/K     Hayes commands to query modem. This command is sent
                         to the Modem to query the modemstatus ( or
                         anything else you want to know ).
                         Maybe you even can change the cofiguration of the
                         modem, I have not tryed.
                         Default: AT&VI2

 MODEMREADYCMD=MRC/K     Command, the modem answers with MODEMCMDOK=MOK/K (OK)
                         Default: AT

 MODEMHANGUPCMD=MHC/K    Command to make the modem drop line.
                         Default: ATH0

 MODEMNOCARRIER=MNC/K    Answer of modem on failed CONNECT
                         Default: NO CARRIER

 MODEMLINEBUSY=MLB/K     Message of modem when line busy.
                         Default: BUSY

 MODEMRING=MRG/K         Message of modem when a call comes in.
                         Default: RING

 MODEMANYCONNECT=MAC/K   Message of modem if a connection of any kind has been
                         established.
                         Default: 'CONNECT?*'     (see LOGINPROMPT)

 MODEMSETTINGHANGUP=MSH/K Command string to send to modem after HANGUP.
                         To avoid this completely use MSH "".
                         Default: ATZ1

 MODEMCMDOK=MOK/K        Answer from Modem if command is ok.
                         Default: OK

 MODEMAACMD=MAC/K        Make modem take phonecall after %d seconds or
                         never when %d == 0
                         Default: ATS0=%d

 MODEMOFFLINECMD=MOC/K   Make modem accept commands again (offline)
                         Default: +++

 MODEMONLINECMD=MLC/K    Bring modem online again
                         Default: ATO

 MODEMTESTCMD=MTC/K      modem to internal loop-back mode
                         Default: AT&T1

 MODEMOFFHOOKCMD=MOH/K   make modem off hook and answer the call.
                         Default: ATA

 MODEMTESTOFFCMD=MTO/K   switch of  modem loopback
                         Default: AT&T0

 MODEMCMDOK=MOK/K        Answer from Modem if command is OK
                         Default: OK

 QUIET/S                 Be quiet to stdout.
                         Default: OFF

 TEST/S                  This is a very helpfull option. Instead of dialing
                         a number, it does AT&T1. This is a modem internal
                         loopback mode. This enables you to do a ping to
                         yourself *over* the modem. You can even do a ftp to
                         your machine and check the max. transmission speed.
                         After this you can QUERY the modem and look for any
                         errors.
                         Default: OFF

 NOSERINIT=NSI/S,        To avoid initialisation of serial line with the
                         parameters from 'ENV:SANA/slipx.config' (But the
                         file itself is read to get the device(name) to open)
                         Default: OFF

 AUTOANSWER=AA/S         Take any incomming call after HANGUP, sana stays
                         online. The parameter RINGS tells the modem how
                         many rings it should wait before offhook.
                         Default: OFF

 NORECONNECT=NRC/S,      No autoanswer during CONNECT (e. g. carrier lost,
                         remote site calls back).
                         Modem takes phone after first ring until you do
                         a HANGUP without AutoAnswer.
                         Default: OFF

 GIVEALLSETTIGNS=ALL/S   This switch is only valid with the DEFAULT command!
                         It shows all current defaults. ENV:Dialup takes
                         effect!


 STACKUSAGE: less than 2000 Bytes.


NOTES:

         The best use for this program is to make it startable with a hotkey.
         (e.g. ToolManager) Commandline:

             'Dialup REPORTFILE T:dialup.report'.

         Think about makeing it resident, if you can afford the memory.

         To stop the program at ANY time press ^C or start it a second time. 
         If you start the program a second time ( e.g. after a BUSY, waiting
         for the REDIALDELAY ) it sends a ^C to its first occurence.
         So, if you have the programm bound to a hotkey, just press it again
         to stop the redialing.

         To reset the modem I use:

             'Dialup HANGUP NODTRIGNORE MODEMSETTINGSHANGUP ATZ'

         or short:

             'Dialup ha ndi msh atz'

         To get a system, taking incomming calls after every reboot, add

             'Dialup CARRIERDETECT AUTOANSWER QUIET RINGS=n'

         to your user-startup. But this only works if no programm is
         causing slip packets beeing sent to the modem, otherwise the
         modem connect could get disturbed.

         I always load the whole network sw in user startup:

             INET:c/config > ENV:HOSTNAME HOSTNAME
             INET:c/config > ENV:USER USER
             INET:c/ifconfig lo0 127.1
             INET:c/ifconfig s0 $hostname -trailers
             INET:c/Route add default <yourslipsite> 0

             Dialup CARRIERDETECT

             IF WARN
                 Ping <yourslipsite>
                 IF NOT WARN
                     Say "Connected to Intearnet"
                 EndIF
             EndIF


 Have fun.   Thomas Kobler
             kobler@mpiw13.mppmu.mpg.de
             +49 89 3241329 (and +49 89 32308311 at work)
             try to talk to me at troja.mppmu.mpg.de or 
                             (pctok.mppmu.mpg.de at work)

    You can send me a mail if you use it.
    This keeps me motivated to fix the bugs.. ahh.. I mean.. improve it!
