| 1 | set_3g_led() { |
| 2 | # set on WRT54G3G only |
| 3 | [ -d /proc/diag ] || return 0 |
| 4 | grep WRT54G3G /proc/diag/model >/dev/null || return 0 |
| 5 | echo "$1" > /proc/diag/led/3g_green |
| 6 | echo "$2" > /proc/diag/led/3g_blue |
| 7 | echo "$3" > /proc/diag/led/3g_blink |
| 8 | } |
| 9 | |
| 10 | scan_3g() { |
| 11 | local device |
| 12 | config_get device "$1" device |
| 13 | |
| 14 | # try to figure out the device if it's invalid |
| 15 | [ -n "$device" -a -e "$device" ] || { |
| 16 | for device in /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/tts/2 /dev/usb/tts/0 /dev/noz0; do |
| 17 | [ -e "$device" ] && { |
| 18 | config_set "$1" device "$device" |
| 19 | break |
| 20 | } |
| 21 | done |
| 22 | } |
| 23 | |
| 24 | # enable 3G with the 3G button by default |
| 25 | local button |
| 26 | config_get button "$1" button |
| 27 | [ -z "$button" ] && { |
| 28 | config_set "$1" button 1 |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | stop_interface_3g() { |
| 33 | stop_interface_ppp "$1" |
| 34 | set_3g_led 0 0 0 |
| 35 | killall gcom >/dev/null 2>/dev/null |
| 36 | } |
| 37 | |
| 38 | setup_interface_3g() { |
| 39 | local iface="$1" |
| 40 | local config="$2" |
| 41 | local chat="/etc/chatscripts/3g.chat" |
| 42 | |
| 43 | local device |
| 44 | config_get device "$config" device |
| 45 | |
| 46 | local maxwait |
| 47 | config_get maxwait "$config" maxwait |
| 48 | maxwait=${maxwait:-20} |
| 49 | while [ ! -e "$device" -a $maxwait -gt 0 ];do # wait for driver loading to catch up |
| 50 | maxwait=$(($maxwait - 1)) |
| 51 | sleep 1 |
| 52 | done |
| 53 | |
| 54 | for module in slhc ppp_generic ppp_async; do |
| 55 | /sbin/insmod $module 2>&- >&- |
| 56 | done |
| 57 | |
| 58 | local apn |
| 59 | config_get apn "$config" apn |
| 60 | |
| 61 | local service |
| 62 | config_get service "$config" service |
| 63 | |
| 64 | local pincode |
| 65 | config_get pincode "$config" pincode |
| 66 | |
| 67 | local mtu |
| 68 | config_get mtu "$config" mtu |
| 69 | |
| 70 | set_3g_led 1 0 1 |
| 71 | |
| 72 | # figure out hardware specific commands for the card |
| 73 | case "$service" in |
| 74 | cdma|evdo) chat="/etc/chatscripts/evdo.chat";; |
| 75 | *) |
| 76 | cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom) |
| 77 | if echo "$cardinfo" | grep Novatel; then |
| 78 | case "$service" in |
| 79 | umts_only) CODE=2;; |
| 80 | gprs_only) CODE=1;; |
| 81 | *) CODE=0;; |
| 82 | esac |
| 83 | mode="AT\$NWRAT=${CODE},2" |
| 84 | elif echo "$cardinfo" | grep Option; then |
| 85 | case "$service" in |
| 86 | umts_only) CODE=1;; |
| 87 | gprs_only) CODE=0;; |
| 88 | *) CODE=3;; |
| 89 | esac |
| 90 | mode="AT_OPSYS=${CODE}" |
| 91 | fi |
| 92 | # Don't assume Option to be default as it breaks with Huawei Cards/Sticks |
| 93 | |
| 94 | test -z "$pincode" || { |
| 95 | PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || { |
| 96 | echo "$config(3g): Failed to set the PIN code." |
| 97 | set_3g_led 0 0 0 |
| 98 | return 1 |
| 99 | } |
| 100 | } |
| 101 | test -z "$mode" || { |
| 102 | MODE="$mode" gcom -d "$device" -s /etc/gcom/setmode.gcom |
| 103 | } |
| 104 | esac |
| 105 | set_3g_led 1 0 0 |
| 106 | |
| 107 | config_set "$config" "connect" "${apn:+USE_APN=$apn }/usr/sbin/chat -t5 -v -E -f $chat" |
| 108 | start_pppd "$config" \ |
| 109 | noaccomp \ |
| 110 | nopcomp \ |
| 111 | novj \ |
| 112 | nobsdcomp \ |
| 113 | noauth \ |
| 114 | lock \ |
| 115 | crtscts \ |
| 116 | ${mtu:+mtu $mtu mru $mtu} \ |
| 117 | 115200 "$device" |
| 118 | } |
| 119 | |