3g.sh 2.4 KB

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