1
0

hso.if-up 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. [ "$IFACE" == "hso0" ] || exit 0
  3. TTY=${IF_HSO_DEVICE:-/dev/ttyHS0}
  4. # wait for card to initialize
  5. COUNT=0
  6. while [ $((COUNT++)) -lt 20 ]; do
  7. [ -c "$TTY" ] && break
  8. [ $COUNT -eq 20 ] && {
  9. logger "$0: '$TTY' not found"
  10. exit 1
  11. }
  12. sleep 1
  13. done
  14. if [ "$IF_PIN" ]; then
  15. COMGTPIN="$IF_PIN" comgt -d "$TTY" PIN
  16. fi
  17. if [ "$IF_APN" ]; then
  18. COMGTAPN="$IF_APN" comgt -d "$TTY" APN
  19. fi
  20. # only run once!
  21. [ -f /tmp/hso-connect ] && exit 0
  22. while :
  23. do
  24. # get connection status
  25. STATUS=$(comgt -s -d "$TTY" /etc/comgt/hsostatus.comgt |
  26. tr -d " " |
  27. grep -v ^$ |
  28. cut -d , -f 2)
  29. # dial if connection status is disabled
  30. if [ "$STATUS" -eq "0" ] ; then
  31. comgt -s -d "$TTY" /etc/comgt/hsoconnect.comgt
  32. DATA=$(comgt -s -d "$TTY" /etc/comgt/hsodata.comgt)
  33. if [ "$?" -ne 0 ] ; then
  34. continue
  35. fi
  36. DATA=$(echo $DATA |
  37. tr -d " " |
  38. grep -v ^$)
  39. IP=$(echo $DATA | cut -d , -f 2)
  40. NS1=$(echo $DATA | cut -d , -f 4)
  41. NS2=$(echo $DATA | cut -d , -f 5)
  42. ip address flush dev hso0 2> /dev/null
  43. ip address add "$IP/32" dev hso0
  44. ip link set hso0 up
  45. def=$(ip route show |grep default | wc -l)
  46. [ $def -eq 1 ] && ip route del default
  47. ip route add default dev hso0
  48. echo "nameserver $NS1" > /etc/resolv.conf
  49. echo "nameserver $NS2" >> /etc/resolv.conf
  50. . /etc/rc.conf
  51. # get time via ntpclient if available
  52. [ -x /usr/sbin/ntpclient ] && ntpclient -s -h pool.ntp.org
  53. # get time via rdate if available
  54. [ -x /usr/sbin/rdate ] && rdate -nv pool.ntp.org
  55. # restart ntpd when enabled
  56. test x"${ntpd:-NO}" = x"NO" || /etc/init.d/ntpd restart
  57. fi
  58. sleep 10
  59. done &
  60. echo $! > /tmp/hso-connect