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