packages: sort network related packages into package/network/
[openwrt/openwrt.git] / package / network / utils / comgt / files / 3g.sh
1 #!/bin/sh
2 INCLUDE_ONLY=1
3
4 . ../netifd-proto.sh
5 . ./ppp.sh
6 init_proto "$@"
7
8 proto_3g_init_config() {
9 no_device=1
10 available=1
11 ppp_generic_init_config
12 proto_config_add_string "device"
13 proto_config_add_string "apn"
14 proto_config_add_string "service"
15 proto_config_add_string "pincode"
16 }
17
18 proto_3g_setup() {
19 local interface="$1"
20 local chat
21
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
27 [ -e "$device" ] || {
28 proto_set_available "$interface" 0
29 return 1
30 }
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
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
73 # wait for carrier to avoid firmware stability bugs
74 [ -n "$SIERRA" ] && {
75 gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
76 }
77 ;;
78 esac
79
80 connect="${apn:+USE_APN=$apn }/usr/sbin/chat -t5 -v -E -f $chat"
81 ppp_generic_setup "$interface" \
82 noaccomp \
83 nopcomp \
84 novj \
85 nobsdcomp \
86 noauth \
87 lock \
88 crtscts \
89 115200 "$device"
90 return 0
91 }
92
93 proto_3g_teardown() {
94 proto_kill_command "$interface"
95 }
96
97 add_protocol 3g