ppp.pre-up 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. [ "$METHOD" == "ppp" ] || exit 0
  3. [ "$IF_USE_TEMPLATE" ] || exit 0
  4. [ -d /var/lock ] || mkdir /var/lock
  5. [ -f "/etc/ppp/templates/$IF_USE_TEMPLATE" ] || {
  6. logger "$0: requested template '/etc/ppp/templates/$IF_USE_TEMPLATE' not found."
  7. exit 1
  8. }
  9. IDLEOPTIONS="persist\nmaxfail 0"
  10. if [ "$IF_PPP_IDLETIME" -gt 0 ]; then
  11. IDLEOTPIONS="idletime $IF_PPP_IDLETIME"
  12. fi
  13. if [ "$IF_PPP_MTU" -gt 0 ] ; then
  14. NETWORKOPTIONS="mtu $IF_PPP_MTU\nmru $IF_PPP_MTU"
  15. fi
  16. REPLACE="
  17. s,#IDLEOPTIONS#,$IDLEOPTIONS,
  18. s,#ENCAPS#,$IF_PPP_ENCAPS,
  19. s,#VPI#,$IF_PPP_VPI,
  20. s,#VCI#,$IF_PPP_VCI,
  21. s,#USERNAME#,$IF_PPP_USERNAME,
  22. s,#PASSWORD#,$IF_PPP_PASSWORD,
  23. s,#DEVICE#,$IF_PPP_DEVICE,
  24. s,#MODEMIP#,$IF_PPP_MODEMIP,
  25. s,#NETWORKOPTIONS#,$NETWORKOPTIONS,
  26. "
  27. sed "$REPLACE" < /etc/ppp/templates/$IF_USE_TEMPLATE > /etc/ppp/peers/$IF_PROVIDER
  28. [ "$IF_PPP_ENCAPS" ] || encap=0
  29. [ "$IF_PPP_PAYLOAD" ] || payload=1
  30. [ "$IF_PPP_VPI" ] || $IF_PPP_VPI=1
  31. [ "$IF_PPP_VCI" ] || $IF_PPP_VCI=32
  32. case "$IF_PPP_PAYLOAD" in
  33. bridged)
  34. payload=1
  35. ;;
  36. routed)
  37. payload=0
  38. ;;
  39. *)
  40. echo "Wrong payload, use either bridged or routed"
  41. exit 1
  42. ;;
  43. esac
  44. case "$IF_PPP_ENCAPS" in
  45. llc)
  46. encap=0
  47. ;;
  48. vc)
  49. encap=1
  50. ;;
  51. *)
  52. echo "Wrong Encapsulation use either llc or vc"
  53. exit 1
  54. ;;
  55. esac
  56. case "$IF_PPP_DEVICE" in
  57. nas*)
  58. count=$(echo $IF_PPP_DEVICE|sed -e "s/nas//")
  59. br2684ctl -b -c $count -e $encap -p $payload -a $IF_PPP_VPI.$IF_PPP_VCI
  60. ip link set up dev $IF_PPP_DEVICE
  61. ;;
  62. esac
  63. case "$IF_USE_TEMPLATE" in
  64. umts)
  65. # set UMTS-LED to green (bit 3)
  66. LED=$(cat /proc/sys/diag)
  67. echo $((LED | 8)) > /proc/sys/diag
  68. # wait for card to initialize
  69. COUNT=0
  70. while [ $((COUNT++)) -lt 20 ]; do
  71. [ -c "$IF_PPP_DEVICE" ] && break
  72. [ $COUNT -eq 20 ] && {
  73. logger "$0: '$IF_PPP_DEVICE' not found"
  74. exit 1
  75. }
  76. sleep 1
  77. done
  78. # wait till the SIM is ready
  79. comgt -s /etc/comgt/waitready.comgt -d $IF_PPP_DEVICE || exit 1
  80. # set pincode
  81. if [ "$IF_UMTS_PINCODE" ]; then
  82. COMGTPIN="$IF_UMTS_PINCODE" comgt PIN -d $IF_PPP_DEVICE || ERROR=1
  83. fi
  84. # set APN
  85. COMGTAPN="$IF_UMTS_APN" comgt APN -d $IF_PPP_DEVICE || ERROR=1
  86. # set umts/gprs mode if available (Option cards only)
  87. case "$IF_UMTS_MODE" in
  88. gprs_only) comgt 2G -d $IF_PPP_DEVICE ;;
  89. umts_only) comgt 3G -d $IF_PPP_DEVICE ;;
  90. umts_first) comgt 3G2G -d $IF_PPP_DEVICE ;;
  91. "") ;;
  92. *) echo "unknown umts-mode, exiting"
  93. ERROR=1
  94. ;;
  95. esac
  96. if [ "$ERROR" == "1" ]; then
  97. echo "$LED" > /proc/sys/diag
  98. exit 1
  99. fi
  100. ;;
  101. esac