3g.sh 2.4 KB

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