ppp.pre-up 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. eth*)
  32. ip link set up dev $IF_PPP_DEVICE
  33. ;;
  34. nas*)
  35. [ "$IF_PPP_ENCAPS" ] || encap=0
  36. [ "$IF_PPP_PAYLOAD" ] || payload=1
  37. case "$IF_PPP_PAYLOAD" in
  38. bridged)
  39. payload=1
  40. ;;
  41. routed)
  42. payload=0
  43. ;;
  44. *)
  45. echo "Wrong payload, use either bridged or routed"
  46. exit 1
  47. ;;
  48. esac
  49. case "$IF_PPP_ENCAPS" in
  50. llc)
  51. encap=0
  52. ;;
  53. vc)
  54. encap=1
  55. ;;
  56. *)
  57. echo "Wrong Encapsulation use either llc or vc"
  58. exit 1
  59. ;;
  60. esac
  61. count=$(echo $IF_PPP_DEVICE|sed -e "s/nas//")
  62. br2684ctl -b -c $count -e $encap -p $payload -a $IF_PPP_VPI.$IF_PPP_VCI
  63. ip link set up dev $IF_PPP_DEVICE
  64. ;;
  65. esac
  66. case "$IF_USE_TEMPLATE" in
  67. umts)
  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_PIN" ]; then
  82. COMGTPIN="$IF_PIN" comgt PIN -d $IF_PPP_DEVICE || exit 1
  83. fi
  84. # set APN
  85. COMGTAPN="$IF_APN" comgt APN -d $IF_PPP_DEVICE || exit 1
  86. # set umts/gprs mode if available (Option cards only)
  87. case "$IF_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 mode, exiting"
  93. exit 1
  94. ;;
  95. esac
  96. ;;
  97. esac