3g.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. set_3g_led() {
  2. # set on WRT54G3G only
  3. [ -f /proc/diag/model ] || return 0
  4. grep -q "WRT54G3G" /proc/diag/model >/dev/null || return 0
  5. echo "$1" > /proc/diag/led/3g_green
  6. echo "$2" > /proc/diag/led/3g_blue
  7. grep -q "WRT54G3G$" /proc/diag/model >/dev/null || return 0
  8. echo "$3" > /proc/diag/led/3g_blink
  9. }
  10. scan_3g() {
  11. local device
  12. config_get device "$1" device
  13. # try to figure out the device if it's invalid
  14. [ -n "$device" -a -e "$device" ] || {
  15. for device in /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/tts/2 /dev/usb/tts/0 /dev/noz0; do
  16. [ -e "$device" ] && {
  17. config_set "$1" device "$device"
  18. break
  19. }
  20. done
  21. }
  22. # enable 3G with the 3G button by default
  23. local button
  24. config_get button "$1" button
  25. [ -z "$button" ] && {
  26. config_set "$1" button 1
  27. }
  28. }
  29. stop_interface_3g() {
  30. stop_interface_ppp "$1"
  31. set_3g_led 0 0 0
  32. killall gcom >/dev/null 2>/dev/null
  33. }
  34. setup_interface_3g() {
  35. local iface="$1"
  36. local config="$2"
  37. local chat="/etc/chatscripts/3g.chat"
  38. local device
  39. config_get device "$config" device
  40. local maxwait
  41. config_get maxwait "$config" maxwait
  42. maxwait=${maxwait:-20}
  43. while [ ! -e "$device" -a $maxwait -gt 0 ];do # wait for driver loading to catch up
  44. maxwait=$(($maxwait - 1))
  45. sleep 1
  46. done
  47. for module in slhc ppp_generic ppp_async; do
  48. /sbin/insmod $module 2>&- >&-
  49. done
  50. local apn
  51. config_get apn "$config" apn
  52. local service
  53. config_get service "$config" service
  54. local pincode
  55. config_get pincode "$config" pincode
  56. local mtu
  57. config_get mtu "$config" mtu
  58. set_3g_led 1 0 1
  59. # figure out hardware specific commands for the card
  60. case "$service" in
  61. cdma|evdo) chat="/etc/chatscripts/evdo.chat";;
  62. *)
  63. cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom)
  64. if echo "$cardinfo" | grep Novatel; then
  65. case "$service" in
  66. umts_only) CODE=2;;
  67. gprs_only) CODE=1;;
  68. *) CODE=0;;
  69. esac
  70. mode="AT\$NWRAT=${CODE},2"
  71. elif echo "$cardinfo" | grep Option; then
  72. case "$service" in
  73. umts_only) CODE=1;;
  74. gprs_only) CODE=0;;
  75. *) CODE=3;;
  76. esac
  77. mode="AT_OPSYS=${CODE}"
  78. fi
  79. # Don't assume Option to be default as it breaks with Huawei Cards/Sticks
  80. test -z "$pincode" || {
  81. PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
  82. echo "$config(3g): Failed to set the PIN code."
  83. set_3g_led 0 0 0
  84. return 1
  85. }
  86. }
  87. test -z "$mode" || {
  88. MODE="$mode" gcom -d "$device" -s /etc/gcom/setmode.gcom
  89. }
  90. esac
  91. set_3g_led 1 0 0
  92. config_set "$config" "connect" "${apn:+USE_APN=$apn }/usr/sbin/chat -t5 -v -E -f $chat"
  93. start_pppd "$config" \
  94. noaccomp \
  95. nopcomp \
  96. novj \
  97. nobsdcomp \
  98. noauth \
  99. lock \
  100. crtscts \
  101. ${mtu:+mtu $mtu mru $mtu} \
  102. 115200 "$device"
  103. }