1
0

3g.sh 2.3 KB

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