1
0

3g.sh 2.5 KB

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