3g.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. INCLUDE_ONLY=1
  3. . ../netifd-proto.sh
  4. . ./ppp.sh
  5. init_proto "$@"
  6. proto_3g_init_config() {
  7. no_device=1
  8. available=1
  9. ppp_generic_init_config
  10. proto_config_add_string "device"
  11. proto_config_add_string "apn"
  12. proto_config_add_string "service"
  13. proto_config_add_string "pincode"
  14. }
  15. proto_3g_setup() {
  16. local interface="$1"
  17. local chat
  18. json_get_var device device
  19. json_get_var apn apn
  20. json_get_var service service
  21. json_get_var pincode pincode
  22. [ -e "$device" ] || {
  23. proto_set_available "$interface" 0
  24. return 1
  25. }
  26. case "$service" in
  27. cdma|evdo)
  28. chat="/etc/chatscripts/evdo.chat"
  29. ;;
  30. *)
  31. chat="/etc/chatscripts/3g.chat"
  32. cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom)
  33. if echo "$cardinfo" | grep -q Novatel; then
  34. case "$service" in
  35. umts_only) CODE=2;;
  36. gprs_only) CODE=1;;
  37. *) CODE=0;;
  38. esac
  39. export MODE="AT\$NWRAT=${CODE},2"
  40. elif echo "$cardinfo" | grep -q Option; then
  41. case "$service" in
  42. umts_only) CODE=1;;
  43. gprs_only) CODE=0;;
  44. *) CODE=3;;
  45. esac
  46. export MODE="AT_OPSYS=${CODE}"
  47. elif echo "$cardinfo" | grep -q "Sierra Wireless"; then
  48. SIERRA=1
  49. elif echo "$cardinfo" | grep -qi huawei; then
  50. case "$service" in
  51. umts_only) CODE="14,2";;
  52. gprs_only) CODE="13,1";;
  53. *) CODE="2,2";;
  54. esac
  55. export MODE="AT^SYSCFG=${CODE},3FFFFFFF,2,4"
  56. fi
  57. if [ -n "$pincode" ]; then
  58. PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
  59. proto_notify_error "$interface" PIN_FAILED
  60. proto_block_restart "$interface"
  61. return 1
  62. }
  63. fi
  64. [ -n "$MODE" ] && gcom -d "$device" -s /etc/gcom/setmode.gcom
  65. # wait for carrier to avoid firmware stability bugs
  66. [ -n "$SIERRA" ] && {
  67. gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
  68. }
  69. ;;
  70. esac
  71. connect="${apn:+USE_APN=$apn }/usr/sbin/chat -t5 -v -E -f $chat"
  72. ppp_generic_setup "$interface" \
  73. noaccomp \
  74. nopcomp \
  75. novj \
  76. nobsdcomp \
  77. noauth \
  78. lock \
  79. crtscts \
  80. 115200 "$device"
  81. return 0
  82. }
  83. proto_3g_teardown() {
  84. proto_kill_command "$interface"
  85. }
  86. add_protocol 3g