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