# /etc/slip.dip
# Author  : Peter Tobias <tobias@et-inf.fho-emden.de>
# Version : 1.0

# Return codes:
#   0  -  ok
#   5  -  non serious problem (they won't cost you money)
#  10  -  serious problem

# Predefined error levels:
# 0 - OK     1 - CONNECT     2 - ERROR     3 - BUSY     4 - NO CARRIER

# Assign the error level 5 to the modem string "NO DIALTONE"
  chatkey       NO\sDIALTONE    5
 
main:
  print Initializing networking parameters ...
  get $local *INSERT_YOUR_LOCAL_IP_NUMBER*
  get $remote *INSERT_THE_REMOTE_IP_NUMBER*

  print Initializing serial port and modem ...
  print
  get $retries 0
  port cua1
  if $errlvl != 0 goto bad_tty
  speed 38400
  reset
  init ATZ1

redial:
# Set max. retries
  if $retries == 10 goto busy_end
  inc $retries
  print [ $retries ] Dialing to $remote [ $rmtip ]

  dial *INSERT_THE_PHONE_NUMBER*
  if $errlvl == 3 goto busy
  if $errlvl == 4 goto no_carrier
  if $errlvl == 5 goto no_dialtone
  if $errlvl != 1 goto error

login:
  wait ogin: 10
  if $errlvl != 0 goto login_err
  send *INSERT_LOGIN_NAME*\n
  wait ord: 5
  if $errlvl != 0 goto passwd_err
  send *INSERT_PASSWORD*\n

### The following lines may be necessary for dynamic IP
# send slip\n
# wait address 5
# if $errlvl != 0 goto no_slip
# get $locip remote 10
# if $errlvl != 0 goto no_ip_address


# mtu 1500
  default
  
  print CONNECTED to $remote with address $local
  mode CSLIP
  goto exit
 

busy:
  print [ $retries ] Dialing failed (BUSY), repeating after delay (15 sec)...
  print
  sleep 15
  goto redial
 
busy_end:
  print The SLIP line is still busy. Try again later ...
  goto exit_warn

bad_tty:
  print Can't open TTY line ...
  goto exit_error

login_err:
  print Error sending login name
  goto exit_error

passwd_err:
  print Error sending password
  goto exit_error

no_carrier:
  print Dialing failed (NO CARRIER)
  goto exit_error

no_ip_address:
  print Can't get (local) IP address from $remote
  goto exit_error

no_slip:
  print Protocol not supported on remote host?
  goto exit_error

no_dialtone:
  print Dialing failed (NO DIALTONE)
  goto exit_warn

error:
  print SLIP to $remote [ $rmtip ] failed

exit_error:
  exit 10

exit_warn:
  exit 5

exit:

