ar71x: use raw squashfs images for TP-Link boards
[openwrt.git] / package / comgt / files-netifd / 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 fi
56
57 if [ -n "$pincode" ]; then
58 PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
59 proto_notify_error "$interface" PIN_FAILED
60 proto_block_restart "$interface"
61 return 1
62 }
63 fi
64 [ -n "$MODE" ] && gcom -d "$device" -s /etc/gcom/setmode.gcom
65
66 # wait for carrier to avoid firmware stability bugs
67 [ -n "$SIERRA" ] && {
68 gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
69 }
70 ;;
71 esac
72
73 connect="${apn:+USE_APN=$apn }/usr/sbin/chat -t5 -v -E -f $chat"
74 ppp_generic_setup "$interface" \
75 noaccomp \
76 nopcomp \
77 novj \
78 nobsdcomp \
79 noauth \
80 lock \
81 crtscts \
82 115200 "$device"
83 return 0
84 }
85
86 proto_3g_teardown() {
87 proto_kill_command "$interface"
88 }
89
90 add_protocol 3g
This page took 0.049519 seconds and 5 git commands to generate.