bootstrap
authorshort <>
Thu, 10 Jul 2003 18:30:44 +0000 (18:30 +0000)
committershort <>
Thu, 10 Jul 2003 18:30:44 +0000 (18:30 +0000)
bin/line9k [new file with mode: 0755]

diff --git a/bin/line9k b/bin/line9k
new file mode 100755 (executable)
index 0000000..55aa27c
--- /dev/null
@@ -0,0 +1,203 @@
+#! /bin/bash
+#
+#      $Id$
+#      http://www.jankratochvil.net/project/line9k/
+#      Modem / Nokia 9110 incoming GSM data gate
+#
+#      /etc/ppp/chap-secrets:
+#              Secrets for authentication using CHAP
+#              client          server  secret          IP addresses
+#              username1a      line9k  secret1a        192.168.90.11
+#              username1b      line9k  secret1b        192.168.90.11
+#              username2       linecr  secret2         192.168.90.12
+#
+#      /etc/inittab:
+#              l9:2345:respawn:/usr/local/sbin/line9k line9k
+#              lc:2345:respawn:/usr/local/sbin/line9k linecr
+#
+#      Charger scheme:
+#                            1N4148
+#              RS232 DTR------|>|------     --------------+--------------     ----AC conn.
+#                                      |   |              |              |   |
+#                                      )  /               |   1N4148     )  /
+#                                      ) /                 ----|>|----   ) /
+#                             680R     ) --                           |  ) --
+#                            ______    |   |                          |  |   |
+#              RS232 GND----|______|---     ----PS/2 +5V     PS/2 GND-+--     ----AC conn.
+#                                   RELSIA05-500                       RAS-0515
+#
+#      Manual charge control:
+#              /usr/local/sbin/line9k charge on        # Force charging on
+#              /usr/local/sbin/line9k charge off       # Automatic charging
+#              /usr/local/sbin/line9k charge           # Query charging force
+
+
+device=$1
+
+# Local IP address of setup pointtopoint interfaces
+LOCAL_IP=192.168.90.10
+
+# Nameserver for remote clients:
+NS=192.168.90.10
+
+# Percent of battery where charging starts
+charge_force_le=50;
+
+# Charger control port
+charge_ttyS=/dev/ttyS0
+
+# Time in seconds to charge the battery after reaching 100% state
+max_limit_time=$[3*60*60];
+
+case $device in
+       line9k)
+               PORT=/dev/ttyS4 # 9110
+               BAUD=19200
+               # Local IP address of setup pointtopoint interfaces
+               REMOTE_IP=192.168.90.11
+               RINGS=1
+               OPTIONS="-crtscts xonxoff asyncmap a0000"
+               # "server" field in /etc/ppp/chap-secrets
+               AUTH_NAME=line9k
+               CHARGE=true
+               ;;
+       linecr)
+               PORT=/dev/ttyS3 # Courier
+               BAUD=57600
+               REMOTE_IP=192.168.90.12
+               RINGS=7
+               OPTIONS="crtscts asyncmap 0"
+               AUTH_NAME=linecr
+               CHARGE=false
+               ;;
+
+##############################################################################
+# Configuration section ends here.
+##############################################################################
+
+       charge)
+               function chargestate
+               {
+                       echo -n "Charging force: "
+                       if test -f $charge_ttyS.charge;then
+                               echo "YES"
+                       else
+                               echo "NO"
+                               fi
+               }
+               chargestate
+               if [ "$2" = on -o "$2" = yes ];then
+                       echo "CHANGED: YES"
+                       touch $charge_ttyS.charge
+                       baud=9600
+               elif [ "$2" = off -o "$2" = no ];then
+                       echo "CHANGED: NO"
+                       rm -f $charge_ttyS.charge
+                       baud=0
+                       fi
+               stty -F $charge_ttyS -hup clocal $baud 2>/dev/null
+               [ -n "$2" ] && chargestate
+               exit 0
+               ;;
+       *)
+               echo "Unknown device: $device"
+               exit 1
+       esac
+
+RING1='"RING" "\c"'
+RINGSTR=""
+while [ $RINGS -gt 0 ];do
+       # FIXME: timeout is not reset after stray ring(s)
+       RINGSTR="$RINGSTR $RING1"
+       RINGS=$[$RINGS-1]
+       done
+LOGGER="logger -i -t $device"
+
+# Use single AT/OK after ATZ to set terminal speed for USRobotics Courier
+exec pppd "$PORT" "$BAUD" modem lock $OPTIONS $LOCAL_IP:$REMOTE_IP ms-dns "$NS" \
+       connect '
+               charge_val_last=-1;
+               baud_last=0;
+               limit_date_last=0;
+               aborts='\''
+                       ABORT       "ERROR"
+                       ABORT       "BUSY"
+                       ABORT       "NO\sANSWER"
+                       ABORT       "NO\sCARRIER"
+                       ABORT       "NO\sDIAL\sTONE"
+                       ABORT       "VOICE"
+                       '\'';
+               rc=3;
+               while test $rc -eq 3; do
+               chat                          \
+                       TIMEOUT     1         \
+                       ""          "ATZ"     \
+                       "OK-ATZ-OK" "AT"      \
+                       ABORT       "+CBC: 0,0"   \
+                       ABORT       "+CBC: 0,25"  \
+                       ABORT       "+CBC: 0,50"  \
+                       ABORT       "+CBC: 0,75"  \
+                       ABORT       "+CBC: 0,100" \
+                       "OK"                  \
+                               '"`if $CHARGE;then echo "AT+CBC" NOTREACHED;fi`"' \
+                                   "\c"      \
+                       ;
+               rc=$?; test $rc -eq 0 -o $rc -ge 4 || exit $rc;
+               if '$CHARGE';then
+                       charge_arr=(0 25 50 75 100);
+                       charge_val=${charge_arr[$[$rc-4]]};
+                       charge_limit_gt=99;
+                       baud=$baud_last;
+                       if test -f $charge_ttyS.charge;then
+                               baud=nocontrol;
+                       else
+                               if test $baud = nocontrol;then
+                                       baud=0;
+                                       fi;
+                               if test $charge_val -le $charge_force_le;then baud=9600;fi;
+                               if test $charge_val -gt $charge_limit_gt;then
+                                       limit_date=$[`date +%s`];
+                                       if test $limit_date_last -eq 0;then
+                                               limit_date_last=$limit_date;
+                                               if test $baud -ne 0;then
+                                                       '"$LOGGER"' "CHARGE state: full-stage charging entered";
+                                                       fi;
+                                       else
+                                               if test $baud -ne 0 -a $[$limit_date-$limit_date_last] -gt $max_limit_time;then
+                                                       '"$LOGGER"' "CHARGE state: full-stage charging terminated";
+                                                       baud=0;
+                                                       fi;
+                                               fi;
+                               else
+                                       limit_date_last=0;
+                                       fi;
+                               fi;
+                       if test $charge_val_last -ne $charge_val -o $baud_last '!=' $baud;then
+                               '"$LOGGER"' "CHARGE state: charge=$charge_val; baud=$baud";
+                               fi;
+                       charge_val_last=$charge_val;
+                       baud_last=$baud;
+                       if test $baud '!=' nocontrol;then
+                               stty -F $charge_ttyS -hup clocal $baud 2>/dev/null;
+                               fi;
+                       fi;
+               chat                          \
+                       $aborts               \
+                       TIMEOUT     590       \
+                       '"$RINGSTR"'          \
+                       ;
+               rc=$?; test $rc -eq 0 -o $rc -eq 3 || exit $rc;
+               done
+               chat -v $aborts               \
+                       TIMEOUT     40        \
+                       REPORT      "CONNECT" \
+                       ""          "ATA"     \
+                       "CONNECT"   "\c"      \
+                       "^M"        "\c"      \
+                       ;
+               rc=$?; test $rc -eq 0 || exit $rc;
+               baud=9600;
+               stty -F $charge_ttyS -hup clocal $baud 2>/dev/null;
+               ' \
+       -ccp nodefaultroute lcp-echo-interval 30 lcp-echo-failure 4 lcp-max-configure 30 -detach debug nologfd kdebug 255 \
+       require-chap -pap auth name $AUTH_NAME