ppp.pre-up 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. [ "$IF_PPP_VPI" ] || IF_PPP_VPI=1
  17. [ "$IF_PPP_VCI" ] || IF_PPP_VCI=32
  18. REPLACE="
  19. s,#IDLEOPTIONS#,$IDLEOPTIONS,
  20. s,#ENCAPS#,$IF_PPP_ENCAPS,
  21. s,#VPI#,$IF_PPP_VPI,
  22. s,#VCI#,$IF_PPP_VCI,
  23. s,#USERNAME#,$IF_PPP_USERNAME,
  24. s,#PASSWORD#,$IF_PPP_PASSWORD,
  25. s,#DEVICE#,$IF_PPP_DEVICE,
  26. s,#MODEMIP#,$IF_PPP_MODEMIP,
  27. s,#NETWORKOPTIONS#,$NETWORKOPTIONS,
  28. "
  29. sed "$REPLACE" < /etc/ppp/templates/$IF_USE_TEMPLATE > /etc/ppp/peers/$IF_PROVIDER
  30. case "$IF_PPP_DEVICE" in
  31. nas*)
  32. [ "$IF_PPP_ENCAPS" ] || encap=0
  33. [ "$IF_PPP_PAYLOAD" ] || payload=1
  34. case "$IF_PPP_PAYLOAD" in
  35. bridged)
  36. payload=1
  37. ;;
  38. routed)
  39. payload=0
  40. ;;
  41. *)
  42. echo "Wrong payload, use either bridged or routed"
  43. exit 1
  44. ;;
  45. esac
  46. case "$IF_PPP_ENCAPS" in
  47. llc)
  48. encap=0
  49. ;;
  50. vc)
  51. encap=1
  52. ;;
  53. *)
  54. echo "Wrong Encapsulation use either llc or vc"
  55. exit 1
  56. ;;
  57. esac
  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. # wait for card to initialize
  66. COUNT=0
  67. while [ $((COUNT++)) -lt 20 ]; do
  68. [ -c "$IF_PPP_DEVICE" ] && break
  69. [ $COUNT -eq 20 ] && {
  70. logger "$0: '$IF_PPP_DEVICE' not found"
  71. exit 1
  72. }
  73. sleep 1
  74. done
  75. # wait till the SIM is ready
  76. comgt -s /etc/comgt/waitready.comgt -d $IF_PPP_DEVICE || exit 1
  77. # set pincode
  78. if [ "$IF_UMTS_PINCODE" ]; then
  79. COMGTPIN="$IF_UMTS_PINCODE" comgt PIN -d $IF_PPP_DEVICE || ERROR=1
  80. fi
  81. # set APN
  82. COMGTAPN="$IF_UMTS_APN" comgt APN -d $IF_PPP_DEVICE || ERROR=1
  83. # set umts/gprs mode if available (Option cards only)
  84. case "$IF_UMTS_MODE" in
  85. gprs_only) comgt 2G -d $IF_PPP_DEVICE ;;
  86. umts_only) comgt 3G -d $IF_PPP_DEVICE ;;
  87. umts_first) comgt 3G2G -d $IF_PPP_DEVICE ;;
  88. "") ;;
  89. *) echo "unknown umts-mode, exiting"
  90. ERROR=1
  91. ;;
  92. esac
  93. ;;
  94. esac